當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。