Java Code Examples for org.apache.commons.pool2.impl.DefaultPooledObject

The following are top voted examples for showing how to use org.apache.commons.pool2.impl.DefaultPooledObject. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: netto_rpc   File: TcpConnectPool.java   Source Code and License 6 votes vote down vote up
public PooledObject<Socket> makeObject() throws Exception {
	// 简单策略随机取服务器,没有考虑权重
	List<ServerAddress> temps = new ArrayList<ServerAddress>();
	temps.addAll(serverGroup.getServers());

	for (int i = temps.size() - 1; i >= 0; i--) {
		int index = new Random(System.currentTimeMillis()).nextInt(temps.size());
		ServerAddress server = temps.get(index);
		try {
			PooledObject<Socket> po = new DefaultPooledObject<Socket>(
					new Socket(server.getIp(), server.getPort()));
			if (logger.isDebugEnabled()) {
				logger.debug("tcpPool makeObject[" + server.getIp() + ":" + server.getPort() + "] success!");
			}
			return po;
		} catch (Exception e) {
			temps.remove(i);
			logger.error("tcpPool makeObject[" + server.getIp() + ":" + server.getPort() + "] failed! "
					+ e.getMessage());
		}
	}
	// 没有可用服务器时,请求一下registry更新服务器信息
	this.updateServerGroup();
	throw new Exception("No server available!");
}
 
Example 2
Project: x7   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
  final HostAndPort hostAndPort = this.hostAndPort.get();
  final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
      soTimeout);

  jedis.connect();
  if (null != this.password) {
    jedis.auth(this.password);
  }
  if (database != 0) {
    jedis.select(database);
  }
  if (clientName != null) {
    jedis.clientSetname(clientName);
  }

  return new DefaultPooledObject<Jedis>(jedis);
}
 
Example 3
Project: microbenchmarks   File: CommonsPool2GenericObjectPoolBenchmark.java   Source Code and License 6 votes vote down vote up
@Override
public void setupObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(poolSize);

    objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() {
        @Override
        public TestObject create() throws Exception {
            return new TestObject(true);
        }

        @Override
        public PooledObject<TestObject> wrap(TestObject testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    }, config);
}
 
Example 4
Project: cachecloud   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
  final HostAndPort hostAndPort = this.hostAndPort.get();
  final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
      soTimeout);

  try {
    jedis.connect();
    if (null != this.password) {
      jedis.auth(this.password);
    }
    if (database != 0) {
      jedis.select(database);
    }
    if (clientName != null) {
      jedis.clientSetname(clientName);
    }
  } catch (JedisException je) {
    jedis.close();
    throw je;
  }

  return new DefaultPooledObject<Jedis>(jedis);

}
 
Example 5
Project: HeliosStreams   File: MQPCFPoolBuilder.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) {
	log("PCFMessageAgent Test");
	final Properties p = new Properties();
	p.setProperty(HOST_KEY, "localhost");
	p.setProperty(PORT_KEY, "1430");
	p.setProperty(CHANNEL_KEY, "JBOSS.SVRCONN");
	MQPCFPoolBuilder poolBuilder = new MQPCFPoolBuilder(p);
	log("Created");
	log("PCF_CTOR: [" + PCF_CTOR + "]");
	Object o = null;
	PooledObject<Object> pooledObject = null;
	try {
		o = poolBuilder.create();
		log("Created Object: [" + o + "]");
		pooledObject = new DefaultPooledObject<Object>(o);
		log("Validating Object....");
		poolBuilder.validateObject(pooledObject);
		//SystemClock.sleep(100000);
		
	} finally {
		if(pooledObject!=null) try { poolBuilder.destroyObject(pooledObject); } catch (Exception x) {}
	}
	
	
}
 
Example 6
Project: cuba   File: AbstractScripting.java   Source Code and License 6 votes vote down vote up
private synchronized GenericKeyedObjectPool<String, Script> getPool() {
    if (pool == null) {
        GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setMaxTotalPerKey(-1);
        poolConfig.setMaxIdlePerKey(globalConfig.getGroovyEvaluationPoolMaxIdle());
        pool = new GenericKeyedObjectPool<>(
                new BaseKeyedPooledObjectFactory<String, Script>() {
                    @Override
                    public Script create(String key) throws Exception {
                        return createScript(key);
                    }

                    @Override
                    public PooledObject<Script> wrap(Script value) {
                        return new DefaultPooledObject<>(value);
                    }
                },
                poolConfig
        );
    }
    return pool;
}
 
Example 7
Project: g2   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
	final Jedis jedis = new Jedis(this.host, this.port, this.timeout);

	jedis.connect();
	if (null != this.password) {
		jedis.auth(this.password);
	}
	if (database != 0) {
		jedis.select(database);
	}
	if (clientName != null) {
		jedis.clientSetname(clientName);
	}

	return new DefaultPooledObject<Jedis>(jedis);
}
 
Example 8
Project: jahhan   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
	final HostAndPort hostAndPort = this.hostAndPort.get();
	final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout);

	jedis.connect();
	if (null != this.password) {
		jedis.auth(this.password);
	}
	if (database != 0) {
		jedis.select(database);
	}
	if (clientName != null) {
		jedis.clientSetname(clientName);
	}

	return new DefaultPooledObject<Jedis>(jedis);
}
 
Example 9
Project: Jedis   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
  final HostAndPort hostAndPort = this.hostAndPort.get();
  final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
      soTimeout);

  jedis.connect();
  if (null != this.password) {
    jedis.auth(this.password);
  }
  if (database != 0) {
    jedis.select(database);
  }
  if (clientName != null) {
    jedis.clientSetname(clientName);
  }

  return new DefaultPooledObject<Jedis>(jedis);
}
 
Example 10
Project: jedis-sr   File: JedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
   public PooledObject<Jedis> makeObject() throws Exception {
   final HostAndPort hostAndPort = this.hostAndPort.get();
final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), this.timeout);

jedis.connect();
if (null != this.password) {
    jedis.auth(this.password);
}
if (database != 0) {
    jedis.select(database);
}
if (clientName != null) {
    jedis.clientSetname(clientName);
}

return new DefaultPooledObject<Jedis>(jedis);
   }
 
Example 11
Project: commons-pool   File: TestPoolUtils.java   Source Code and License 6 votes vote down vote up
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    if (calledMethods == null) {
        return null;
    }
    calledMethods.add(method.getName());
    if (boolean.class.equals(method.getReturnType())) {
        return Boolean.FALSE;
    } else if (int.class.equals(method.getReturnType())) {
        return Integer.valueOf(0);
    } else if (long.class.equals(method.getReturnType())) {
        return Long.valueOf(0);
    } else if (Object.class.equals(method.getReturnType())) {
        return new Object();
    } else if (PooledObject.class.equals(method.getReturnType())) {
        return new DefaultPooledObject<>(new Object());
    } else {
        return null;
    }
}
 
Example 12
Project: commons-dbcp   File: PooledConnectionImpl.java   Source Code and License 6 votes vote down vote up
/**
 * My {@link KeyedPooledObjectFactory} method for creating
 * {@link PreparedStatement}s.
 * @param key the key for the {@link PreparedStatement} to be created
 */
@Override
public PooledObject<PoolablePreparedStatement<PStmtKeyCPDS>> makeObject(final PStmtKeyCPDS key) throws Exception {
    if (null == key) {
        throw new IllegalArgumentException();
    }
    // _openPstmts++;
    if (null == key.getResultSetType()
            && null == key.getResultSetConcurrency()) {
        if (null == key.getAutoGeneratedKeys()) {
            return new DefaultPooledObject<>(new PoolablePreparedStatement<>(
                    connection.prepareStatement(key.getSql()),
                    key, pstmtPool, delegatingConnection));
        }
        return new DefaultPooledObject<>(new PoolablePreparedStatement<>(
                        connection.prepareStatement(key.getSql(),
                                key.getAutoGeneratedKeys().intValue()),
                        key, pstmtPool, delegatingConnection));
    }
    return new DefaultPooledObject<>(new PoolablePreparedStatement<>(
            connection.prepareStatement(key.getSql(),
                    key.getResultSetType().intValue(),
                    key.getResultSetConcurrency().intValue()),
                    key, pstmtPool, delegatingConnection));
}
 
Example 13
Project: commons-dbcp   File: CPDSConnectionFactory.java   Source Code and License 6 votes vote down vote up
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject() {
    PooledConnectionAndInfo pci;
    try {
        PooledConnection pc = null;
        if (_username == null) {
            pc = _cpds.getPooledConnection();
        } else {
            pc = _cpds.getPooledConnection(_username, _password);
        }

        if (pc == null) {
            throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
        }

        // should we add this object as a listener or the pool.
        // consider the validateObject method in decision
        pc.addConnectionEventListener(this);
        pci = new PooledConnectionAndInfo(pc, _username, _password);
        pcMap.put(pc, pci);
    } catch (final SQLException e) {
        throw new RuntimeException(e.getMessage());
    }
    return new DefaultPooledObject<>(pci);
}
 
Example 14
Project: spring-ldap   File: DirContextPooledObjectFactoryTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testValidateObject() throws Exception {
    when(dirContextValidatorMock
            .validateDirContext(DirContextType.READ_ONLY, dirContextMock))
            .thenReturn(true);

    final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
    objectFactory.setDirContextValidator(dirContextValidatorMock);

    PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
    final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
    assertThat(valid).isTrue();

    //Check exception in validator
    DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class);

    when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock))
            .thenThrow(new RuntimeException("Failed to validate"));
    objectFactory.setDirContextValidator(secondDirContextValidatorMock);

    final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
    assertThat(valid2).isFalse();
}
 
Example 15
Project: argo   File: BinaryJedisFactory.java   Source Code and License 6 votes vote down vote up
@Override
public PooledObject<BinaryJedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), this.timeout);

    jedis.connect();
    if (null != this.password) {
        jedis.auth(this.password);
    }
    if (database != 0) {
        jedis.select(database);
    }
    if (clientName != null) {
        jedis.clientSetname(clientName);
    }

    return new DefaultPooledObject<BinaryJedis>(jedis);
}
 
Example 16
Project: nighthawk   File: JaRedisFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    JaRedis.Builder builder = new JaRedis.Builder();
    builder
            .host(hostAndPort.getHost())
            .port(hostAndPort.getPort())
            .connectionTimeout(connectionTimeout)
            .soTimeout(soTimeout);
    Jedis jedis = builder.build();
    try {
        jedis.connect();
        if (null != this.password) {
            jedis.auth(this.password);
        }
        if (database != 0) {
            jedis.select(database);
        }
        if (clientName != null) {
            jedis.clientSetname(clientName);
        }
    } catch (JedisException je) {
        jedis.close();
        throw je;
    }
    return new DefaultPooledObject<>(jedis);
}
 
Example 17
Project: JRediClients   File: JedisFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<Jedis> makeObject() throws Exception {
	final HostAndPort hostAndPort = this.hostAndPort.get();
	final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout, soTimeout,
			password, database, ssl, sslSocketFactory, sslParameters, hostnameVerifier);

	try {
		jedis.connect();
		//if (password != null && !password.isEmpty()) {
		//	jedis.auth(password);
		//}
		//if (database != 0) {
		//	jedis.select(database);
		//}
		if (clientName != null) {
			String reply = jedis.clientSetname(clientName);
			if (!"OK".equalsIgnoreCase(reply)) {
				logger.info("reply={}",reply);
			}
		}
	} catch (JedisException je) {
		jedis.close();
		throw je;
	}

	return new DefaultPooledObject<Jedis>(jedis);

}
 
Example 18
Project: jmeter-sshmon   File: SSHSessionFactoryIT.java   Source Code and License 5 votes vote down vote up
@Test
public void testWrap() throws Exception {
    session = new JSch().getSession(""); // dummy
    PooledObject<Session> actual = instance.wrap(session);
    assertTrue(actual instanceof DefaultPooledObject);
    assertEquals(session, actual.getObject());
}
 
Example 19
Project: presto-kudu   File: KuduClientFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<KuduClient> makeObject()
        throws Exception
{
    KuduClient kuduClient = null;

    try {
        kuduClient = new KuduClient.KuduClientBuilder(masterAddresses).build();
    }
    catch (Exception e) {
        throw new KuduClientPoolException(e);
    }

    return new DefaultPooledObject<KuduClient>(kuduClient);
}
 
Example 20
Project: ThriftJ   File: ThriftConnectionFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<TTransport> makeObject(ThriftServer thriftServer) throws Exception {
	TSocket tsocket = new TSocket(thriftServer.getHost(), thriftServer.getPort());
	tsocket.setTimeout(timeout);
	TFramedTransport transport = new TFramedTransport(tsocket);
	
	transport.open();
	DefaultPooledObject<TTransport> result = new DefaultPooledObject<TTransport>(transport);
	logger.trace("Make new thrift connection: {}:{}", thriftServer.getHost(), thriftServer.getPort());
	
	return result;
}
 
Example 21
Project: trpc   File: TrpcClientFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<T> makeObject(ThriftServerInfo info) throws Exception {
    T client = transportProvider.apply(info);
    client.open();
    DefaultPooledObject<T> result = new DefaultPooledObject<>(client);
    log.debug("make new ThriftClient:{}", info);
    return result;
}
 
Example 22
Project: microbenchmarks   File: CommonsPool2SoftReferenceObjectPoolBenchmark.java   Source Code and License 5 votes vote down vote up
@Override
public void setupObjectPool() {
    objectPool = new SoftReferenceObjectPool<>(new BasePooledObjectFactory<TestObject>() {
        @Override
        public TestObject create() throws Exception {
            return new TestObject(true);
        }

        @Override
        public PooledObject<TestObject> wrap(TestObject testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    });
}
 
Example 23
Project: herddb   File: BasicHerdDBDataSource.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<HDBConnection> makeObject() throws Exception {
    HDBClient _client = getClient();
    HDBConnection connection = _client.openConnection();
    connection.setDiscoverTablespaceFromSql(false);
    return new DefaultPooledObject<>(connection);
}
 
Example 24
Project: q-thrift   File: DefaultThriftConnectionPoolImpl.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<TTransport> makeObject(ThriftServerInfo info) throws Exception {
    TTransport transport = transportProvider.apply(info);
    transport.open();
    DefaultPooledObject<TTransport> result = new DefaultPooledObject<>(transport);
    logger.trace("make new thrift connection:{}", info);
    return result;
}
 
Example 25
Project: timely   File: PooledCloseableHttpClientFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject makeObject() throws Exception {
    RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
            .setConnectTimeout(connectTimeout).setSocketTimeout(socketTimeout).build();
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setDefaultRequestConfig(requestConfig);
    builder.setConnectionTimeToLive(connectionTimeToLive, TimeUnit.MILLISECONDS);
    return new DefaultPooledObject(builder.build());
}
 
Example 26
Project: jasperreports   File: ProcessFactory.java   Source Code and License 5 votes vote down vote up
@Override
public void activateObject(PooledObject<PhantomJSProcess> pooledObject) throws Exception
{
	super.activateObject(pooledObject);
	
	PhantomJSProcess process = pooledObject.getObject();
	if (process.hasEnded())
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " has ended");
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " has ended");
	}
	
	long borrowedCount = ((DefaultPooledObject<PhantomJSProcess>) pooledObject).getBorrowedCount();
	if (borrowedCount >= expirationCount)
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " borrow count " + borrowedCount 
					+ " exceeded expiration count " + expirationCount);
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " borrow count exceeded");
	}
	
	long now = System.currentTimeMillis();
	if (now >= pooledObject.getCreateTime() + expirationTime)
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " expiration time " + expirationTime 
					+ " from " + pooledObject.getCreateTime() + " exceeded");
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " expiration time exceeded");
	}
}
 
Example 27
Project: schedule   File: NettyChannelFactory.java   Source Code and License 5 votes vote down vote up
public PooledObject<NettyChannel> makeObject() throws Exception {
	NettyChannel channel = new NettyChannel(bootstrap);
	if (log.isDebugEnabled()) {
		log.debug("创建连接池对象:" + channel);
	}
	return new DefaultPooledObject<NettyChannel>(channel);
}
 
Example 28
Project: x-pipe   File: NettyKeyedPoolClientFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<NettyClient> makeObject(InetSocketAddress key) throws Exception {

	ChannelFuture f = b.connect(key);
	f.get(connectTimeoutMilli, TimeUnit.MILLISECONDS);
	Channel channel = f.channel();
	logger.debug("[makeObject]{}", channel);
	NettyClient nettyClient = new DefaultNettyClient(channel);
	channel.attr(NettyClientHandler.KEY_CLIENT).set(nettyClient);
	return new DefaultPooledObject<NettyClient>(nettyClient);
}
 
Example 29
Project: x-pipe   File: NettyClientFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<NettyClient> makeObject() throws Exception {

	ChannelFuture f = b.connect(address);
	f.get(connectTimeoutMilli, TimeUnit.MILLISECONDS);
	Channel channel = f.channel();
	logger.info("[makeObject]{}", channel);
	NettyClient nettyClient = new DefaultNettyClient(channel);
	channel.attr(NettyClientHandler.KEY_CLIENT).set(nettyClient);
	return new DefaultPooledObject<NettyClient>(nettyClient);
}
 
Example 30
Project: OpenUnison   File: PooledMessageProducerFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<MessageProducerHolder> makeObject() throws Exception {
	Connection con = prov.getQueueConnection();
	Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
	Queue q = session.createQueue(taskQueueName);
	MessageProducer mp = session.createProducer(q);
	return new DefaultPooledObject(new MessageProducerHolder(con,mp,session));
}
 
Example 31
Project: opencucina   File: ConversationConfiguration.java   Source Code and License 5 votes vote down vote up
private BasePooledObjectFactory<PollableChannel> messagePoolFactory() {
    return new BasePooledObjectFactory<PollableChannel>() {
            @Override
            public PollableChannel create()
                throws Exception {
                return new QueueChannel(10);
            }

            @Override
            public PooledObject<PollableChannel> wrap(PollableChannel obj) {
                return new DefaultPooledObject<PollableChannel>(obj);
            }
        };
}
 
Example 32
Project: opencucina   File: OperativeFactoryImplTest.java   Source Code and License 5 votes vote down vote up
/**
 *
 *
 * @throws Exception .
 */
@Before
public void setUp()
    throws Exception {
    MockitoAnnotations.initMocks(this);
    factory = new OperativeFactoryImpl(activePoolFactory, passivePoolFactory);
    when(operative.getCallbackChannel()).thenReturn(callbackChannel);
    when(activePoolFactory.makeObject())
        .thenReturn(new DefaultPooledObject<Operative>(operative));
    when(passivePoolFactory.makeObject())
        .thenReturn(new DefaultPooledObject<Operative>(poperative));
}
 
Example 33
Project: smtp-connection-pool   File: SmtpConnectionFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<ClosableSmtpConnection> makeObject() throws Exception {
  LOG.debug("makeObject");

  Transport transport = transportFactory.getTransport(session);
  connectionStrategy.connect(transport);

  DefaultClosableSmtpConnection closableSmtpTransport = new DefaultClosableSmtpConnection(transport);
  initDefaultListeners(closableSmtpTransport);

  return new DefaultPooledObject(closableSmtpTransport);
}
 
Example 34
Project: connection-pool-client   File: RedisConnectionFactoryOldTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test_1() throws Exception {

    RedisConnectionFactoryOld factory = new RedisConnectionFactoryOld(
            RedisConfig.DEFAULT_HOST, RedisConfig.DEFAULT_PORT,
            RedisConfig.DEFAULT_TIMEOUT, RedisConfig.DEFAULT_TIMEOUT,
            RedisConfig.DEFAULT_PASSWORD, RedisConfig.DEFAULT_DATABASE,
            RedisConfig.DEFAULT_CLIENTNAME);

    factory.validateObject(new DefaultPooledObject<Jedis>(factory
            .makeObject().getObject()));

    factory.destroyObject(new DefaultPooledObject<Jedis>(factory
            .makeObject().getObject()));
}
 
Example 35
Project: hashaggregator   File: KryoPool.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<Kryo> makeObject() throws Exception {
    Kryo kryo = new Kryo();
    //TODO: can automatically discover all types in the package type and register it
    //Reflections reflections = new Reflections(packageOfTypes);

    kryo.register(Map.class);
    kryo.register(HashMap.class);
    return new DefaultPooledObject<Kryo>(kryo);
}
 
Example 36
Project: thrift-pool-client   File: DefaultThriftConnectionPoolImpl.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<TTransport> makeObject(ThriftServerInfo info) throws Exception {
    TTransport transport = transportProvider.apply(info);
    transport.open();
    DefaultPooledObject<TTransport> result = new DefaultPooledObject<>(transport);
    logger.trace("make new thrift connection:{}", info);
    return result;
}
 
Example 37
Project: hashaggregator   File: KryoPool.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<Kryo> makeObject() throws Exception {
    Kryo kryo = new Kryo();
    //TODO: can automatically discover all types in the package type and register it
    //Reflections reflections = new Reflections(packageOfTypes);

    kryo.register(Map.class);
    kryo.register(HashMap.class);
    return new DefaultPooledObject<Kryo>(kryo);
}
 
Example 38
Project: dataflux   File: KryoPool.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<Kryo> makeObject() throws Exception {
    Kryo kryo = new Kryo();
    //TODO: can automatically discover all types in the package type and register it
    //Reflections reflections = new Reflections(packageOfTypes);

    kryo.register(WebTxnData.class);
    kryo.register(Map.class);
    kryo.register(HashMap.class);
    return new DefaultPooledObject<Kryo>(kryo);
}
 
Example 39
Project: cattle   File: ListenerPoolObjectFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<FutureEventListener> makeObject() throws Exception {
    String key = prefix + Math.abs(random.nextLong());
    FutureEventListener listener = new FutureEventListener(eventService, key);
    Future<?> future = eventService.subscribe(key, listener);
    AsyncUtils.get(future, 10, TimeUnit.SECONDS);
    return new DefaultPooledObject<>(listener);
}
 
Example 40
Project: cloud-cattle   File: ListenerPoolObjectFactory.java   Source Code and License 5 votes vote down vote up
@Override
public PooledObject<FutureEventListener> makeObject() throws Exception {
    String key = "reply." + Math.abs(random.nextLong());
    FutureEventListener listener = new FutureEventListener(eventService, key);
    Future<?> future = eventService.subscribe(key, listener);
    future.get();
    return new DefaultPooledObject<FutureEventListener>(listener);
}