当前位置: 首页>>代码示例>>Java>>正文


Java ObjectPool类代码示例

本文整理汇总了Java中org.apache.commons.pool2.ObjectPool的典型用法代码示例。如果您正苦于以下问题:Java ObjectPool类的具体用法?Java ObjectPool怎么用?Java ObjectPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObjectPool类属于org.apache.commons.pool2包,在下文中一共展示了ObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPersistenceWithHALeaseManagerPreservingLease

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerPreservingLease(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true always
        doReturn(true).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(2)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例2: testPersistenceWithHALeaseManagerFailingToPreserveLease1

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease1(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true first and false later for stillInLeasePeriod
        doReturn(true).doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(2)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例3: testPersistenceWithHALeaseManagerFailingToPreserveLease2

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease2(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return false for stillInLeasePeriod
        doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(1)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例4: testPersistenceWithHALeaseManagerFailingToPreserveLease3

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease3(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true first and false later for stillInLeasePeriod and raise
        // an exception when flush
        // Configure mock writer to flush unsuccessfully
        doThrow(new IOException("Unable to write")).when(mockWriter).flush();
        doReturn(true).doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(1)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();

    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:25,代码来源:TestPersistenceProcessor.java

示例5: configureHandlers

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private PersistenceProcessorHandler[] configureHandlers(TSOServerConfig tsoConfig,
                                                        LeaseManager leaseManager,
                                                        ObjectPool<Batch> batchPool)
        throws Exception {
    PersistenceProcessorHandler[] handlers = new PersistenceProcessorHandler[tsoConfig.getNumConcurrentCTWriters()];
    for (int i = 0; i < tsoConfig.getNumConcurrentCTWriters(); i++) {
        handlers[i] = new PersistenceProcessorHandler(metrics,
                                                      "localhost:1234",
                                                      leaseManager,
                                                      commitTable,
                                                      new ReplyProcessorImpl(new BlockingWaitStrategy(), metrics, panicker, batchPool),
                                                      retryProcessor,
                                                      new RuntimeExceptionPanicker());
    }
    return handlers;
}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:17,代码来源:TestPersistenceProcessor.java

示例6: testRetriedRequestForAnExistingTxReturnsCommit

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
@Test(timeOut = 10_000)
public void testRetriedRequestForAnExistingTxReturnsCommit() throws Exception {
    ObjectPool<Batch> batchPool = new BatchPoolModule(new TSOServerConfig()).getBatchPool();

    // The element to test
    RetryProcessor retryProc = new RetryProcessorImpl(new YieldingWaitStrategy(), metrics, commitTable, replyProc, panicker, batchPool);

    // Test we'll reply with a commit for a retry request when the start timestamp IS in the commit table
    commitTable.getWriter().addCommittedTransaction(ST_TX_1, CT_TX_1);
    retryProc.disambiguateRetryRequestHeuristically(ST_TX_1, channel, new MonitoringContext(metrics));
    ArgumentCaptor<Long> firstTSCapture = ArgumentCaptor.forClass(Long.class);
    ArgumentCaptor<Long> secondTSCapture = ArgumentCaptor.forClass(Long.class);

    verify(replyProc, timeout(100).times(1)).sendCommitResponse(firstTSCapture.capture(),
                                                                secondTSCapture.capture(),
                                                                any(Channel.class));

    long startTS = firstTSCapture.getValue();
    long commitTS = secondTSCapture.getValue();
    assertEquals(startTS, ST_TX_1, "Captured timestamp should be the same as ST_TX_1");
    assertEquals(commitTS, CT_TX_1, "Captured timestamp should be the same as CT_TX_1");

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:24,代码来源:TestRetryProcessor.java

示例7: testRetriedRequestForInvalidatedTransactionReturnsAnAbort

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
@Test(timeOut = 10_000)
public void testRetriedRequestForInvalidatedTransactionReturnsAnAbort() throws Exception {

    // Invalidate the transaction
    commitTable.getClient().tryInvalidateTransaction(ST_TX_1);

    // Pre-start verification: Validate that the transaction is invalidated
    // NOTE: This test should be in the a test class for InMemoryCommitTable
    Optional<CommitTimestamp> invalidTxMarker = commitTable.getClient().getCommitTimestamp(ST_TX_1).get();
    Assert.assertTrue(invalidTxMarker.isPresent());
    Assert.assertEquals(invalidTxMarker.get().getValue(), InMemoryCommitTable.INVALID_TRANSACTION_MARKER);

    ObjectPool<Batch> batchPool = new BatchPoolModule(new TSOServerConfig()).getBatchPool();

    // The element to test
    RetryProcessor retryProc = new RetryProcessorImpl(new YieldingWaitStrategy(), metrics, commitTable, replyProc, panicker, batchPool);

    // Test we return an Abort to a retry request when the transaction id IS in the commit table BUT invalidated
    retryProc.disambiguateRetryRequestHeuristically(ST_TX_1, channel, new MonitoringContext(metrics));
    ArgumentCaptor<Long> startTSCapture = ArgumentCaptor.forClass(Long.class);
    verify(replyProc, timeout(100).times(1)).sendAbortResponse(startTSCapture.capture(), any(Channel.class));
    long startTS = startTSCapture.getValue();
    Assert.assertEquals(startTS, ST_TX_1, "Captured timestamp should be the same as NON_EXISTING_ST_TX");

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:26,代码来源:TestRetryProcessor.java

示例8: initialize

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
@Activate
public void initialize(final ComponentContext context) {
  this.subServiceName = PropertiesUtil.toString(context.getProperties().get(PROPERTY_SUBSERVICENAME), "");
  scriptResources = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_SCRIPTS_PATHS), new String[0]);
  int poolTotalSize = PropertiesUtil.toInteger(context.getProperties().get(PROPERTY_POOL_TOTAL_SIZE), 20);
  JavacriptEnginePoolFactory javacriptEnginePoolFactory = new JavacriptEnginePoolFactory(createLoader(scriptResources), null);
  ObjectPool<JavascriptEngine> pool = createPool(poolTotalSize, javacriptEnginePoolFactory);
  this.engine = new ReactScriptEngine(this, pool, isReloadScripts(context), finder, dynamicClassLoaderManager);
  this.listener = new JcrResourceChangeListener(repositoryConnectionFactory, new JcrResourceChangeListener.Listener() {
    @Override
    public void changed(String script) {
      createScripts();
    }
  }, subServiceName);
  this.listener.activate(scriptResources);
  this.createScripts();
}
 
开发者ID:sinnerschrader,项目名称:aem-react,代码行数:18,代码来源:ReactScriptEngineFactory.java

示例9: createPool

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private ObjectPool<PoolableConnection> createPool(String connectionString) {
    // A ConnectionFactory that the pool will use to create Connections.
    ConnectionFactory connectionFactory =
            new DriverManagerConnectionFactory(connectionString, null);
    // PoolableConnectionFactory wraps the real Connections with the
    // classes that implement the pooling functionality.
    PoolableConnectionFactory poolableConnectionFactory =
            new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setValidationQuery("SELECT 1");

    // Actual pool of connections.
    GenericObjectPool<PoolableConnection> connectionPool =
            new GenericObjectPool<>(poolableConnectionFactory);
    int connMax = getConfig()
            .getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
    connectionPool.setMaxTotal(connMax);
    connectionPool.setTestOnBorrow(true);
    // Set the factory's pool property to the owning pool.
    poolableConnectionFactory.setPool(connectionPool);

    return connectionPool;
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:23,代码来源:ConnectionManager.java

示例10: getConnection

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
/**
 * Will return a dbConnection for a given information topic.
 * @param sourceName Data source name
 * @return topicDbConnection connection topic
 */
public Connection getConnection(String sourceName) {
	Validate.notEmpty(sourceName, "Null or blank sourceName not allowed");
	Validate.isTrue(this.initRun, "Moneta not properly initialized.");
	
	ObjectPool connectionPool = connectionPoolMap.get(sourceName);
	if (connectionPool == null) {
		throw new MonetaException("Data Source Not Found")
			.addContextValue("sourceName", sourceName);
	}
	
	try {
		return (Connection)connectionPool.borrowObject();
	} catch (Exception e) {
		throw new MonetaException("Error creating JDBC connection")
			.addContextValue("sourceName", sourceName);
	}
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:23,代码来源:MonetaConfiguration.java

示例11: main

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

    String file = "C:\\Windows\\System32\\drivers\\etc\\hosts";
    ObjectPool<StringBuilder> objectPool = new SoftReferenceObjectPool(new StringBuilderFactory());
    ReaderUtil readerUtil = new ReaderUtil(objectPool);
    Reader reader = new FileReader(new File(file));
    readerUtil.readToString(new FileReader(new File(file)));
    readerUtil.readToString(new FileReader(new File(file)));
    readerUtil.readToString(new FileReader(new File(file)));
    readerUtil.readToString(new FileReader(new File(file)));
    readerUtil.readToString(new FileReader(new File(file)));
    readerUtil.readToString(new FileReader(new File(file)));
    String content = readerUtil.readToString(new FileReader(new File(file)));
    System.out.println(content);

  }
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:17,代码来源:ReaderUtilTest.java

示例12: setup

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
private void setup() {
	try {
		Class.forName(driver);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
			url, username, password);
	PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
			connectionFactory, null);
	ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
			poolableConnectionFactory);
	poolableConnectionFactory.setPool(connectionPool);
	PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
			connectionPool);
	this.dataSource = dataSource;
	logger.debug("get DataSource");
}
 
开发者ID:int32bit,项目名称:openstack-java-sdk,代码行数:19,代码来源:DataBaseAccessor.java

示例13: createPool

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
public static DataSource createPool(ConnectionFactory connectionFactory, int isolation) {
 
 
 
   PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
       connectionFactory, null);
   poolableConnectionFactory.setMaxConnLifetimeMillis(3000);
   poolableConnectionFactory.setDefaultAutoCommit(false);
   poolableConnectionFactory.setDefaultReadOnly(true);
   poolableConnectionFactory
       .setDefaultTransactionIsolation(isolation);
   ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
       poolableConnectionFactory);
   poolableConnectionFactory.setPool(connectionPool);
   PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
       connectionPool);
   return dataSource;
}
 
开发者ID:objectof-group,项目名称:objectof,代码行数:19,代码来源:ISql.java

示例14: createPool

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
public static DataSource createPool(String aName)
{
  ResourceBundle bundle = ResourceBundle.getBundle(aName);
  String password = bundle.getString("PWD");
  String principal = bundle.getString("PRINCIPAL");
  String conn = bundle.getString("CONNECTION");
  DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
      conn, principal, password);
  PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
      connectionFactory, null);
  ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
      poolableConnectionFactory);
  poolableConnectionFactory.setPool(connectionPool);
  PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
      connectionPool);
  return dataSource;
}
 
开发者ID:objectof-group,项目名称:objectof,代码行数:18,代码来源:ISql.java

示例15: stop

import org.apache.commons.pool2.ObjectPool; //导入依赖的package包/类
@Stop
public void stop() {
    LOG.info("Mqttv3Client stoping!");

    if (clnt != null) {
        for (Entry<String, ObjectPool<IMqttAsyncClient>> entry : clnt.entrySet()) {
            try {
                entry.getValue().close();
            } catch (Exception e) {
                LOG.error(e.getMessage(), e.fillInStackTrace());
            }
        }
        clnt = null;
    }

    LOG.info("Mqttv3Client finish stoping!");
}
 
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:Mqttv3ClientImpl.java


注:本文中的org.apache.commons.pool2.ObjectPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。