Exemplo n.º 1
0
  private void dispose(Throwable throwable) {
    synchronized (this) {
      if (disposed) {
        return;
      }
      disposed = true;
    }

    notifyListeners();
    for (Iterator<DisposeListener> i = disposeListeners.iterator(); i.hasNext(); ) {
      i.next().notifyDispose(this);
    }

    _iProtocol.terminate();

    try {
      _messageDispatcher.terminate();

      try {
        _xConnection.close();
      } catch (com.sun.star.io.IOException e) {
        System.err.println(getClass().getName() + ".dispose - IOException:" + e);
      }

      if (Thread.currentThread() != _messageDispatcher && _messageDispatcher.isAlive()) {
        _messageDispatcher.join(1000);
        if (_messageDispatcher.isAlive()) {
          _messageDispatcher.interrupt();
          _messageDispatcher.join();
        }
      }

      // interrupt all jobs queued by this bridge
      _iThreadPool.dispose(throwable);

      // release all out-mapped objects and all in-mapped proxies:
      freeHolders();
      // assert _java_environment instanceof java_environment;
      ((java_environment) _java_environment).revokeAllProxies();

      proxyFactory.dispose();

      if (DEBUG) {
        if (_life_count.get() != 0) {
          System.err.println(
              getClass().getName() + ".dispose - life count (proxies left):" + _life_count);
        }
        _java_environment.list();
      }

      // clear members
      _xConnection = null;
      _java_environment = null;
      _messageDispatcher = null;
    } catch (InterruptedException e) {
      System.err.println(getClass().getName() + ".dispose - InterruptedException:" + e);
    }
  }
Exemplo n.º 2
0
  public Object sendRequest(String oid, Type type, String operation, Object[] params)
      throws Throwable {
    Object result = null;

    checkDisposed();

    ThreadId threadId = _iThreadPool.getThreadId();
    Object handle = _iThreadPool.attach(threadId);
    try {
      boolean sync;
      try {
        sync =
            _iProtocol.writeRequest(
                oid, TypeDescription.getTypeDescription(type), operation, threadId, params);
      } catch (IOException e) {
        dispose(e);
        throw (DisposedException) new DisposedException(e.toString()).initCause(e);
      }
      if (sync && Thread.currentThread() != _messageDispatcher) {
        result = _iThreadPool.enter(handle, threadId);
      }
    } finally {
      _iThreadPool.detach(handle, threadId);
      if (operation.equals("release")) release(); // kill this bridge, if this was the last proxy
    }

    if (DEBUG) System.err.println("##### " + getClass().getName() + ".sendRequest left:" + result);

    // On the wire (at least in URP), the result of queryInterface is
    // transported as an ANY, but in Java it shall be transported as a
    // direct reference to the UNO object (represented as a Java Object),
    // never boxed in a com.sun.star.uno.Any:
    if (operation.equals("queryInterface") && result instanceof Any) {
      Any a = (Any) result;
      if (a.getType().getTypeClass() == TypeClass.INTERFACE) {
        result = a.getObject();
      } else {
        result = null; // should never happen
      }
    }

    return result;
  }
Exemplo n.º 3
0
  public void sendReply(boolean exception, ThreadId threadId, Object result) {
    if (DEBUG) {
      System.err.println(
          "##### " + getClass().getName() + ".sendReply: " + exception + " " + result);
    }

    checkDisposed();

    try {
      _iProtocol.writeReply(exception, threadId, result);
    } catch (IOException e) {
      dispose(e);
      throw (DisposedException) (new DisposedException("unexpected " + e).initCause(e));
    } catch (RuntimeException e) {
      dispose(e);
      throw e;
    } catch (Error e) {
      dispose(e);
      throw e;
    }
  }
Exemplo n.º 4
0
 public java_remote_bridge(
     IEnvironment java_environment, IEnvironment remote_environment, Object[] args)
     throws Exception {
   _java_environment = java_environment;
   String proto = (String) args[0];
   _xConnection = (XConnection) args[1];
   _xInstanceProvider = (XInstanceProvider) args[2];
   if (args.length > 3) {
     _name = (String) args[3];
   }
   String attr;
   int i = proto.indexOf(',');
   if (i >= 0) {
     protocol = proto.substring(0, i);
     attr = proto.substring(i + 1);
   } else {
     protocol = proto;
     attr = null;
   }
   _iProtocol =
       (IProtocol)
           Class.forName("com.sun.star.lib.uno.protocols." + protocol + "." + protocol)
               .getConstructor(
                   new Class[] {
                     IBridge.class, String.class, InputStream.class, OutputStream.class
                   })
               .newInstance(
                   new Object[] {
                     this,
                     attr,
                     new XConnectionInputStream_Adapter(_xConnection),
                     new XConnectionOutputStream_Adapter(_xConnection)
                   });
   proxyFactory = new ProxyFactory(this, this);
   _iThreadPool = ThreadPoolManager.create();
   _messageDispatcher = new MessageDispatcher();
   _messageDispatcher.start();
   _iProtocol.init();
 }