Update ooo320-m1
[ooovba.git] / bridges / test / java_uno / nativethreadpool / Relay.java
blob7dfa64146a08ab0f7722628662542027ac546501
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Relay.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package test.javauno.nativethreadpool;
33 import com.sun.star.bridge.BridgeExistsException;
34 import com.sun.star.bridge.XBridgeFactory;
35 import com.sun.star.bridge.XInstanceProvider;
36 import com.sun.star.comp.helper.Bootstrap;
37 import com.sun.star.comp.loader.FactoryHelper;
38 import com.sun.star.connection.AlreadyAcceptingException;
39 import com.sun.star.connection.ConnectionSetupException;
40 import com.sun.star.connection.Acceptor;
41 import com.sun.star.connection.XAcceptor;
42 import com.sun.star.connection.XConnection;
43 import com.sun.star.lang.WrappedTargetRuntimeException;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.lang.XSingleServiceFactory;
46 import com.sun.star.registry.XRegistryKey;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XComponentContext;
50 public final class Relay implements XRelay, XSource {
51 public void start(XSource source) {
52 this.source = source;
53 XComponentContext context;
54 try {
55 context = Bootstrap.createInitialComponentContext(null);
56 } catch (RuntimeException e) {
57 throw e;
58 } catch (com.sun.star.uno.Exception e) {
59 throw new WrappedTargetRuntimeException(e.toString(), this, e);
60 } catch (Exception e) {
61 throw new com.sun.star.uno.RuntimeException(e.toString(), this);
63 final XAcceptor acceptor = Acceptor.create(context);
64 final XBridgeFactory factory;
65 try {
66 factory = UnoRuntime.queryInterface(
67 XBridgeFactory.class,
68 context.getServiceManager().createInstanceWithContext(
69 "com.sun.star.bridge.BridgeFactory", context));
70 } catch (com.sun.star.uno.Exception e) {
71 throw new WrappedTargetRuntimeException(e.toString(), this, e);
73 new Thread() {
74 public void run() {
75 try {
76 // Use "127.0.0.1" instead of "localhost", see #i32281#:
77 factory.createBridge(
78 "", "urp",
79 acceptor.accept("socket,host=127.0.0.1,port=3831"),
80 new XInstanceProvider() {
81 public Object getInstance(String instanceName) {
82 return Relay.this;
84 });
85 } catch (AlreadyAcceptingException e) {
86 e.printStackTrace(System.err);
87 } catch (ConnectionSetupException e) {
88 e.printStackTrace(System.err);
89 } catch (BridgeExistsException e) {
90 e.printStackTrace(System.err);
91 } catch (com.sun.star.lang.IllegalArgumentException e) {
92 e.printStackTrace(System.err);
95 }.start();
96 try {
97 Thread.sleep(3000); // wait for new thread to accept connection
98 } catch (InterruptedException e) {
99 Thread.currentThread().interrupt();
100 throw new com.sun.star.uno.RuntimeException(e.toString(), this);
104 public long get() {
105 return source.get();
108 public static XSingleServiceFactory __getServiceFactory(
109 String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
111 return implName.equals(implementationName)
112 ? FactoryHelper.getServiceFactory(
113 Relay.class, serviceName, multiFactory, regKey)
114 : null;
117 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
118 return FactoryHelper.writeRegistryServiceInfo(
119 implementationName, serviceName, regKey);
122 private static final String implementationName
123 = "test.javauno.nativethreadpool.comp.Relay";
124 private static final String serviceName
125 = "test.javauno.nativethreadpool.Relay";
127 private XSource source;