Package org.serviceconnector.net.connection

Examples of org.serviceconnector.net.connection.IConnection


  /** {@inheritDoc} */
  @Override
  protected void channelIdle(ChannelHandlerContext ctx, IdleState state, long lastActivityTimeMillis)
      throws Exception {
    super.channelIdle(ctx, state, lastActivityTimeMillis);
    IConnection connection = this.connectionContext.getConnection();
    if (ConnectionLogger.isEnabledFull()) {
      ConnectionLogger.logKeepAlive(this.getClass().getSimpleName(), connection.getHost(), 0, this.connectionContext
          .getConnection().getNrOfIdlesInSequence());
    }
    IIdleConnectionCallback callback = this.connectionContext.getIdleCallback();
    callback.connectionIdle(connection);
  }
View Full Code Here


  /** {@inheritDoc} */
  @Override
  public void send(SCMPMessage message, int timeoutMillis, ISCMPMessageCallback callback) throws Exception {
    // return an already connected live instance
    IConnection connection = this.connectionPool.getConnection();
    ConnectionContext connectionContext = connection.getContext();
    try {
      ISCMPMessageCallback requesterCallback = new RequesterSCMPCallback(callback, connectionContext);
      // setting up operation timeout after successful send
      TimeoutWrapper timeoutWrapper = new TimeoutWrapper((ITimeout) requesterCallback);
      RequesterSCMPCallback reqCallback = (RequesterSCMPCallback) requesterCallback;
      @SuppressWarnings("unchecked")
      ScheduledFuture<TimeoutWrapper> timeout = (ScheduledFuture<TimeoutWrapper>) AppContext.otiScheduler.schedule(
          timeoutWrapper, (long) timeoutMillis, TimeUnit.MILLISECONDS);
      reqCallback.setOperationTimeout(timeout);
      reqCallback.setTimeoutMillis(timeoutMillis);
      connection.send(message, requesterCallback);
    } catch (Exception ex) {
      this.connectionPool.freeConnection(connection);
      throw ex;
    }
  }
View Full Code Here

  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  public void send(SCMPMessage message, int timeoutMillis, ISCMPMessageCallback scmpCallback) throws Exception {
    // return an already connected live instance
    IConnection connection = this.connectionPool.getConnection();
    ConnectionContext connectionContext = connection.getContext();

    try {
      ISCMPMessageCallback requesterCallback = null;
      // differ if message is large or not, sending procedure is different
      if (message.isLargeMessage()) {
        // SCMPLargeRequest handles splitting, works like an iterator
        SCMPCompositeSender largeResponse = new SCMPCompositeSender(message);
        requesterCallback = new SCRequesterSCMPCallback(message, scmpCallback, connectionContext, largeResponse,
            msgSequenceNr);
        // setting up operation timeout after successful send
        TimeoutWrapper timeoutWrapper = new TimeoutWrapper((ITimeout) requesterCallback);
        SCRequesterSCMPCallback reqCallback = (SCRequesterSCMPCallback) requesterCallback;
        ScheduledFuture<TimeoutWrapper> timeout = (ScheduledFuture<TimeoutWrapper>) AppContext.otiScheduler.schedule(
            timeoutWrapper, (long) timeoutMillis, TimeUnit.MILLISECONDS);
        reqCallback.setOperationTimeout(timeout);
        reqCallback.setTimeoutMillis(timeoutMillis);
        // extract first part message & send
        SCMPMessage part = largeResponse.getFirst();
        // handling msgSequenceNr
        if (SCMPMessageSequenceNr.necessaryToWrite(message.getMessageType())) {
          part.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr.getCurrentNr());
        }
        // send
        connection.send(part, requesterCallback);
      } else {
        requesterCallback = new SCRequesterSCMPCallback(message, scmpCallback, connectionContext, msgSequenceNr);
        // setting up operation timeout after successful send
        TimeoutWrapper timeoutWrapper = new TimeoutWrapper((ITimeout) requesterCallback);
        SCRequesterSCMPCallback reqCallback = (SCRequesterSCMPCallback) requesterCallback;
        ScheduledFuture<TimeoutWrapper> timeout = (ScheduledFuture<TimeoutWrapper>) AppContext.otiScheduler.schedule(
            timeoutWrapper, (long) timeoutMillis, TimeUnit.MILLISECONDS);
        reqCallback.setOperationTimeout(timeout);
        reqCallback.setTimeoutMillis(timeoutMillis);
        // handling msgSequenceNr
        if (SCMPMessageSequenceNr.necessaryToWrite(message.getMessageType())) {
          message.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr.getCurrentNr());
        }
        // process send
        connection.send(message, requesterCallback);
      }
    } catch (Exception ex) {
      this.connectionPool.freeConnection(connection);
      throw ex;
    }
View Full Code Here

            this.writeBean(writer, connectionContext);
            writer.writeEndElement();
            continue;
          }
          if (value instanceof IConnection) {
            IConnection connection = (IConnection) value;
            writer.writeStartElement("connection");
            this.writeBean(writer, connection);
            writer.writeEndElement();
            continue;
          }
View Full Code Here

   * Description: Gets one connection and frees it<br>
   * Expectation: passes
   */
  @Test
  public void t01_GetAndFreeConnection() throws Exception {
    IConnection connection = connectionPool.getConnection();
    connectionPool.freeConnection(connection);
  }
View Full Code Here

  public void t20_KeepAliveActive() throws Exception {
    connectionPool.setMaxConnections(1);
    connectionPool.setMinConnections(1);
    connectionPool.initMinConnections();
    Thread.sleep((long) ((this.keepAliveSeconds * 1.4) * Constants.SEC_TO_MILLISEC_FACTOR));
    IConnection connection = connectionPool.getConnection();
    Assert.assertTrue(connection.getNrOfIdlesInSequence() > 0);
    connectionPool.freeConnection(connection);
  }
View Full Code Here

   * Expectation: passes
   */
  @Test
  public void t21_NoKeepAliveForUsedConnection() throws Exception {
    connectionPool.setMaxConnections(1);
    IConnection connection = connectionPool.getConnection();
    Thread.sleep((long) ((this.keepAliveSeconds * 1.4) * Constants.SEC_TO_MILLISEC_FACTOR));
    Assert.assertTrue(connection.getNrOfIdlesInSequence() == 0);
    Assert.assertTrue(connection.isConnected());
  }
View Full Code Here

   * Expectation: passes
   */
  @Test
  public void t30_CloseAfterFreeConnection() throws Exception {
    connectionPool.setCloseOnFree(true);
    IConnection connection = connectionPool.getConnection();
    IConnection connection2 = connectionPool.getConnection();
    connectionPool.freeConnection(connection);
    Assert.assertFalse(connection.isConnected());
    connectionPool.freeConnection(connection2);
    Assert.assertTrue(connection2.isConnected());
  }
View Full Code Here

    connectionPool.setMinConnections(2);
    connectionPool.setCloseAfterKeepAlive(false);
    connectionPool.initMinConnections();
    Thread.sleep((long) ((this.keepAliveSeconds * 1.5) * Constants.SEC_TO_MILLISEC_FACTOR)
        * Constants.DEFAULT_NR_OF_KEEP_ALIVES_TO_CLOSE);
    IConnection connection = connectionPool.getConnection();
    Assert.assertTrue(connection.getNrOfIdlesInSequence() > Constants.DEFAULT_NR_OF_KEEP_ALIVES_TO_CLOSE);
    Assert.assertTrue(connection.isConnected());
    connectionPool.freeConnection(connection);
    connectionPool.setCloseAfterKeepAlive(true);
  }
View Full Code Here

    message.setMessageType(SCMPMsgType.ATTACH);
    message.setHeader(SCMPHeaderAttributeKey.SC_VERSION, SCVersion.CURRENT.toString());
    message.setHeader(SCMPHeaderAttributeKey.LOCAL_DATE_TIME, ldt);

    for (int i = 0; i < 10000; i++) {
      IConnection connection = connectionPool.getConnection();
      TestCallback cbk = new TestCallback();
      connection.send(message, cbk);
      cbk.getMessageSync(1000);
      connectionPool.freeConnection(connection);
      if ((i + 1) % 5000 == 0) {
        testLogger.info("connection nr " + (i + 1) + "...");
      }
View Full Code Here

TOP

Related Classes of org.serviceconnector.net.connection.IConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.