@Override
 public void destroyObject(String key, PooledObject<CustomSocketClient> value) throws Exception {
   log.trace("destroyObject... {}", key);
   if (value.getObject().isConnected()) {
     value.getObject().disconnect();
   }
 }
Example #2
0
  @Test(timeOut = 10_000)
  public void testBatchFactoryFunctionality() throws Exception {

    // Component to test
    Batch.BatchFactory factory = new Batch.BatchFactory(BATCH_SIZE);

    // Check the factory creates a new batch properly...
    Batch batch = factory.create();
    assertTrue(batch.isEmpty(), "Batch should be empty");
    assertFalse(batch.isFull(), "Batch shouldn't be full");
    assertEquals(batch.getNumEvents(), 0, "Num events should be 0");

    // ...and is wrapped in to a pooled object
    PooledObject<Batch> pooledBatch = factory.wrap(batch);
    assertEquals(pooledBatch.getObject(), batch);

    // Put some elements in the batch...
    batch.addTimestamp(ANY_ST, channel, monCtx);
    batch.addCommit(ANY_ST, ANY_CT, channel, monCtx);
    batch.addCommitRetry(ANY_ST, channel, monCtx);
    batch.addAbort(ANY_ST, channel, monCtx);
    assertFalse(batch.isEmpty(), "Batch should contain elements");
    assertFalse(batch.isFull(), "Batch should NOT be full");
    assertEquals(batch.getNumEvents(), 4, "Num events should be 4");

    // ... and passivate the object through the factory. It should reset the state of the batch
    factory.passivateObject(pooledBatch);
    assertTrue(batch.isEmpty(), "Batch should NOT contain elements");
    assertFalse(batch.isFull(), "Batch should NOT be full");
    assertEquals(batch.getNumEvents(), 0, "Num events should be 0");
  }
 @Override
 public void activateObject(String key, PooledObject<CustomSocketClient> value) throws Exception {
   log.trace("activateObject... {}", key);
   if (!value.getObject().isConnected()) {
     log.trace("reconnect... {}", key);
     connect(key, value.getObject());
   }
 }
Example #4
0
 @Override
 public void activateObject(PooledObject<Jedis> pooledJedis) throws Exception {
   final BinaryJedis jedis = pooledJedis.getObject();
   if (jedis.getDB() != database) {
     jedis.select(database);
   }
 }
 @Override
 public void destroyObject(ThriftServerAddress info, PooledObject<TTransport> p)
     throws Exception {
   TTransport transport = p.getObject();
   if (transport != null && transport.isOpen()) {
     transport.close();
     logger.trace("close thrift connection:{}", info);
   }
 }
  @Override
  public void destroyObject(PooledObject<SimpleThread> p) throws Exception {
    if (p instanceof SimpleThread) {
      SimpleThread simpleThread = (SimpleThread) p;
      debug("Destroy simple thread : " + simpleThread.getName());
    }

    p.getObject().destroy();
  }
 @Override
 public boolean validateObject(ThriftServerAddress info, PooledObject<TTransport> p) {
   try {
     // System.out.println(p.getObject()
     // +" open "+p.getObject().isOpen());
     return p.getObject().isOpen();
   } catch (Throwable e) {
     logger.error("fail to validate tsocket:{}", info, e);
     return false;
   }
 }
Example #8
0
  @Override
  public void destroyObject(PooledObject<Jedis> pooledJedis) throws Exception {
    final BinaryJedis jedis = pooledJedis.getObject();
    if (jedis.isConnected()) {
      try {
        try {
          jedis.quit();
        } catch (Exception e) {
        }
        jedis.disconnect();
      } catch (Exception e) {

      }
    }
  }
Example #9
0
  @Override
  public boolean validateObject(PooledObject<Jedis> pooledJedis) {
    final BinaryJedis jedis = pooledJedis.getObject();
    try {
      HostAndPort hostAndPort = this.hostAndPort.get();

      String connectionHost = jedis.getClient().getHost();
      int connectionPort = jedis.getClient().getPort();

      return hostAndPort.getHost().equals(connectionHost)
          && hostAndPort.getPort() == connectionPort
          && jedis.isConnected()
          && jedis.ping().equals("PONG");
    } catch (final Exception e) {
      return false;
    }
  }
 @Override
 public boolean validateObject(PooledObject<TcpClient> p) {
   return p.getObject().isConnected();
 }
 public void destroyObject(InetSocketAddress key, PooledObject<StorageServer> p) throws Exception {
   p.getObject().close();
 }
 @Override
 public void passivateObject(PooledObject<SdcKafkaProducer> p) throws Exception {
   LOG.debug("Deactivating Kafka producer '{}'", p.getObject());
   p.getObject().clearMessages();
 }
Example #13
0
 @Override
 public void destroyObject(AdapterToIndexMapping key, PooledObject<IndexWriter> p)
     throws Exception {
   super.destroyObject(key, p);
   p.getObject().close();
 }
 @Override
 public boolean validateObject(String key, PooledObject<CustomSocketClient> value) {
   boolean validate = value.getObject().isAvailable();
   log.trace("validateObject... {}, {}", key, validate);
   return validate;
 }
 @Override
 public void destroyObject(PooledObject<SdcKafkaProducer> p) throws Exception {
   LOG.debug("Destroying Kafka producer '{}'", p.getObject());
   p.getObject().destroy();
 }
 @Override
 public void activateObject(PooledObject<TcpClient> p) throws Exception {
   p.getObject().connect();
 }
 @Override
 public void destroyObject(PooledObject<TcpClient> p) throws Exception {
   p.getObject().close();
 }
 @Override
 public void activateObject(PooledObject<SdcKafkaProducer> p) throws Exception {
   LOG.debug("Activating Kafka producer '{}'", p.getObject());
 }