コード例 #1
0
  public HARMIServerImpl(
      HAPartition partition,
      String replicantName,
      Class intf,
      Object handler,
      int port,
      RMIClientSocketFactory clientSocketFactory,
      RMIServerSocketFactory serverSocketFactory,
      InetAddress bindAddress)
      throws Exception {
    this.handler = handler;
    this.log = Logger.getLogger(this.getClass());
    this.intf = intf;
    this.key = partition.getPartitionName() + "/" + replicantName;

    // Obtain the hashes for the supported handler interfaces
    Class[] ifaces = handler.getClass().getInterfaces();
    for (int i = 0; i < ifaces.length; i++) {
      Map tmp = MarshalledInvocation.methodToHashesMap(ifaces[i]);
      invokerMap.putAll(tmp);
    }

    if (bindAddress != null) {
      // If there is no serverSocketFactory use a default
      if (serverSocketFactory == null) serverSocketFactory = new DefaultSocketFactory(bindAddress);
      else {
        // See if the server socket supports setBindAddress(String)
        try {
          Class[] parameterTypes = {String.class};
          Class ssfClass = serverSocketFactory.getClass();
          Method m = ssfClass.getMethod("setBindAddress", parameterTypes);
          Object[] args = {bindAddress.getHostAddress()};
          m.invoke(serverSocketFactory, args);
        } catch (NoSuchMethodException e) {
          log.warn("Socket factory does not support setBindAddress(String)");
          // Go with default address
        } catch (Exception e) {
          log.warn("Failed to setBindAddress=" + bindAddress + " on socket factory", e);
          // Go with default address
        }
      }
    }

    this.rmistub =
        (RemoteStub)
            UnicastRemoteObject.exportObject(
                this,
                port,
                clientSocketFactory,
                serverSocketFactory); // casting is necessary because interface has changed in
                                      // JDK>=1.2
    this.target =
        new RefreshProxiesHATarget(partition, replicantName, rmistub, HATarget.ENABLE_INVOCATIONS);

    HARMIServer.rmiServers.put(key, this);
  }
コード例 #2
0
  public HARMIResponse invoke(long clientViewId, MarshalledInvocation mi) throws Exception {
    mi.setMethodMap(invokerMap);
    Method method = mi.getMethod();

    try {
      HARMIResponse rsp = new HARMIResponse();
      if (clientViewId != target.getCurrentViewId()) {
        rsp.newReplicants = new ArrayList(target.getReplicants());
        rsp.currentViewId = target.getCurrentViewId();
      }

      rsp.response = method.invoke(handler, mi.getArguments());
      return rsp;
    } catch (IllegalAccessException iae) {
      throw iae;
    } catch (IllegalArgumentException iae) {
      throw iae;
    } catch (java.lang.reflect.InvocationTargetException ite) {
      throw (Exception) ite.getTargetException();
    }
  }