Esempio 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);
    }
  }
Esempio 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;
  }