Ejemplo n.º 1
0
  void listenMembershipEvents(Address ownerConnectionAddress) {
    initialListFetchedLatch = new CountDownLatch(1);
    try {
      ClientMessage clientMessage = RegisterMembershipListenerParameters.encode();

      Connection connection = connectionManager.getConnection(ownerConnectionAddress);
      if (connection == null) {
        System.out.println("FATAL connection null " + ownerConnectionAddress);
        throw new IllegalStateException(
            "Can not load initial members list because owner connection is null. "
                + "Address "
                + ownerConnectionAddress);
      }
      ClientInvocation invocation = new ClientInvocation(client, this, clientMessage, connection);
      invocation.invoke().get();
      waitInitialMemberListFetched();

    } catch (Exception e) {
      if (client.getLifecycleService().isRunning()) {
        if (LOGGER.isFinestEnabled()) {
          LOGGER.warning(
              "Error while registering to cluster events! -> " + ownerConnectionAddress, e);
        } else {
          LOGGER.warning(
              "Error while registering to cluster events! -> "
                  + ownerConnectionAddress
                  + ", Error: "
                  + e.toString());
        }
      }
    }
  }
Ejemplo n.º 2
0
  private ClientInvocation(
      HazelcastClientInstanceImpl client,
      EventHandler handler,
      ClientMessage clientMessage,
      int partitionId,
      Address address,
      Connection connection) {
    this.lifecycleService = client.getLifecycleService();
    this.invocationService = client.getInvocationService();
    this.executionService = client.getClientExecutionService();
    this.listenerService = (ClientListenerServiceImpl) client.getListenerService();
    this.handler = handler;
    this.clientMessage = clientMessage;
    this.partitionId = partitionId;
    this.address = address;
    this.connection = connection;
    final ClientProperties clientProperties = client.getClientProperties();

    int waitTime = clientProperties.getInvocationTimeoutSeconds().getInteger();
    long retryTimeoutInSeconds =
        waitTime > 0
            ? waitTime
            : Integer.parseInt(ClientProperties.PROP_INVOCATION_TIMEOUT_SECONDS_DEFAULT);

    clientInvocationFuture = new ClientInvocationFuture(this, client, clientMessage, handler);
    this.retryCountLimit = retryTimeoutInSeconds / RETRY_WAIT_TIME_IN_SECONDS;

    int interval = clientProperties.getHeartbeatInterval().getInteger();
    this.heartBeatInterval =
        interval > 0 ? interval : Integer.parseInt(PROP_HEARTBEAT_INTERVAL_DEFAULT);
  }
Ejemplo n.º 3
0
 public ClientConnection(
     HazelcastClientInstanceImpl client,
     IOSelector in,
     IOSelector out,
     int connectionId,
     SocketChannelWrapper socketChannelWrapper)
     throws IOException {
   final Socket socket = socketChannelWrapper.socket();
   this.connectionManager = client.getConnectionManager();
   this.serializationService = client.getSerializationService();
   this.lifecycleService = client.getLifecycleService();
   this.socketChannelWrapper = socketChannelWrapper;
   this.connectionId = connectionId;
   this.readHandler = new ClientReadHandler(this, in, socket.getReceiveBufferSize());
   this.writeHandler = new ClientWriteHandler(this, out, socket.getSendBufferSize());
 }
  void listenMembershipEvents(Address ownerConnectionAddress) {
    initialListFetchedLatch = new CountDownLatch(1);
    try {
      ClientMessage clientMessage = ClientMembershipListenerCodec.encodeRequest();

      Connection connection = connectionManager.getConnection(ownerConnectionAddress);
      if (connection == null) {
        throw new IllegalStateException(
            "Can not load initial members list because owner connection is null. "
                + "Address "
                + ownerConnectionAddress);
      }
      ClientInvocation invocation =
          new ClientListenerInvocation(
              client,
              this,
              clientMessage,
              connection,
              new ClientMessageDecoder() {
                @Override
                public <T> T decodeClientMessage(ClientMessage clientMessage) {
                  return (T) ClientMembershipListenerCodec.decodeResponse(clientMessage).response;
                }
              });
      invocation.invoke().get();
      waitInitialMemberListFetched();

    } catch (Exception e) {
      if (client.getLifecycleService().isRunning()) {
        if (LOGGER.isFinestEnabled()) {
          LOGGER.warning(
              "Error while registering to cluster events! -> " + ownerConnectionAddress, e);
        } else {
          LOGGER.warning(
              "Error while registering to cluster events! -> "
                  + ownerConnectionAddress
                  + ", Error: "
                  + e.toString());
        }
      }
    }
  }
Ejemplo n.º 5
0
  protected ClientInvocation(
      HazelcastClientInstanceImpl client,
      ClientMessage clientMessage,
      int partitionId,
      Address address,
      Connection connection) {
    this.lifecycleService = client.getLifecycleService();
    this.invocationService = client.getInvocationService();
    this.executionService = client.getClientExecutionService();
    this.clientMessage = clientMessage;
    this.partitionId = partitionId;
    this.address = address;
    this.connection = connection;

    HazelcastProperties hazelcastProperties = client.getProperties();
    long waitTime = hazelcastProperties.getMillis(INVOCATION_TIMEOUT_SECONDS);
    long waitTimeResolved =
        waitTime > 0 ? waitTime : Integer.parseInt(INVOCATION_TIMEOUT_SECONDS.getDefaultValue());
    retryTimeoutPointInMillis = System.currentTimeMillis() + waitTimeResolved;

    logger = ((ClientInvocationServiceSupport) invocationService).invocationLogger;
    clientInvocationFuture = new ClientInvocationFuture(this, client, clientMessage, logger);
  }