コード例 #1
0
  public SmartClientConnectionManager(
      HazelcastClient client, Authenticator authenticator, LoadBalancer loadBalancer) {
    this.authenticator = authenticator;
    this.client = client;
    ClientConfig config = client.getClientConfig();
    router = new Router(loadBalancer);

    // init socketInterceptor
    SocketInterceptorConfig sic = config.getSocketInterceptorConfig();
    if (sic != null && sic.isEnabled()) {
      SocketInterceptor implementation = (SocketInterceptor) sic.getImplementation();
      if (implementation == null && sic.getClassName() != null) {
        try {
          implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance();
        } catch (Throwable e) {
          logger.severe("SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e);
        }
      }
      if (implementation != null) {
        if (!(implementation instanceof MemberSocketInterceptor)) {
          logger.severe(
              "SocketInterceptor must be instance of " + MemberSocketInterceptor.class.getName());
          implementation = null;
        } else {
          logger.info("SocketInterceptor is enabled");
        }
      }
      if (implementation != null) {
        socketInterceptor = implementation;
        socketInterceptor.init(sic.getProperties());
      } else {
        socketInterceptor = null;
      }
    } else {
      socketInterceptor = null;
    }

    poolSize = config.getConnectionPoolSize();
    int connectionTimeout = config.getConnectionTimeout();
    heartbeat =
        new HeartBeatChecker(
            connectionTimeout,
            client.getSerializationService(),
            client.getClientExecutionService());
    socketOptions = config.getSocketOptions();
  }
コード例 #2
0
  private SocketInterceptor initSocketInterceptor(SocketInterceptorConfig sic) {
    SocketInterceptor implementation = null;
    if (sic != null && sic.isEnabled()) {
      implementation = (SocketInterceptor) sic.getImplementation();
      if (implementation == null && sic.getClassName() != null) {
        try {
          implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance();
        } catch (Throwable e) {
          LOGGER.severe("SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e);
        }
      }
    }

    if (implementation != null) {
      implementation.init(sic.getProperties());
    }
    return implementation;
  }