本文整理匯總了Java中org.infinispan.manager.EmbeddedCacheManager.start方法的典型用法代碼示例。如果您正苦於以下問題:Java EmbeddedCacheManager.start方法的具體用法?Java EmbeddedCacheManager.start怎麽用?Java EmbeddedCacheManager.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.infinispan.manager.EmbeddedCacheManager
的用法示例。
在下文中一共展示了EmbeddedCacheManager.start方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testStart
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
/**
* Run multiple instances and check that all instances are online.
*
* @throws ExecutionException
* @throws TimeoutException
*/
@Test
public void testStart() throws IOException, InterruptedException, ExecutionException {
int nodeNumber = 3;
prepareCluster(nodeNumber, null);
// start test instance
EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder("node main", null).build();
this.cacheManager = cacheManager;
cacheManager.start();
LOGGER.debug("waiting nodes");
try {
waitNodes(cacheManager, nodeNumber + 1, 30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
Assert.fail(String.format("Node number %d not reached before timeout", nodeNumber + 1));
}
}
示例2: run
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
@Override
public void run() {
final EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder(nodeName, taskName).build();
cacheManager.start();
while (!Thread.currentThread().isInterrupted()) {
try {
Object object = new Object();
// synchronized to become object owner
LOGGER.debug("Start main loop");
synchronized (object) {
object.wait();
}
} catch (InterruptedException e) {
LOGGER.warn("Thread interrupted while wait");
Thread.currentThread().interrupt();
}
}
}
示例3: testConfigBuilder
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
public void testConfigBuilder() {
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();
Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).location(tmpDataDirectory)
.expiredLocation(tmpExpiredDirectory).implementationType(LevelDBStoreConfiguration.ImplementationType.AUTO).build();
StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
assertTrue(cacheLoaderConfig instanceof LevelDBStoreConfiguration);
LevelDBStoreConfiguration leveldbConfig = (LevelDBStoreConfiguration) cacheLoaderConfig;
assertEquals(tmpDataDirectory, leveldbConfig.location());
assertEquals(tmpExpiredDirectory, leveldbConfig.expiredLocation());
EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);
cacheManager.defineConfiguration("testCache", cacheConfig);
cacheManager.start();
Cache<String, String> cache = cacheManager.getCache("testCache");
cache.put("hello", "there");
cache.stop();
cacheManager.stop();
}
示例4: testLegacyJavaConfig
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
@Test(enabled = false, description = "ISPN-3388")
public void testLegacyJavaConfig() {
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();
Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).addProperty("location", tmpDataDirectory)
.addProperty("expiredLocation", tmpExpiredDirectory).addProperty("implementationType", LevelDBStoreConfiguration.ImplementationType.AUTO.toString()).build();
EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);
cacheManager.defineConfiguration("testCache", cacheConfig);
cacheManager.start();
Cache<String, String> cache = cacheManager.getCache("testCache");
cache.put("hello", "there legacy java");
cache.stop();
cacheManager.stop();
}
示例5: testConfigBuilder
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
public void testConfigBuilder() {
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();
Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(MapDBStoreConfigurationBuilder.class)
.location(tmpDirectory)
.compression(true)
.build();
StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
assertTrue(cacheLoaderConfig instanceof MapDBStoreConfiguration);
MapDBStoreConfiguration config = (MapDBStoreConfiguration) cacheLoaderConfig;
assertEquals(true, config.compression());
EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);
cacheManager.defineConfiguration("testCache", cacheConfig);
cacheManager.start();
Cache<String, String> cache = cacheManager.getCache("testCache");
cache.put("hello", "there");
cache.stop();
cacheManager.stop();
}
示例6: testConfigBuilder
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
public void testConfigBuilder() {
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();
Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(OffheapStoreConfigurationBuilder.class)
.compression(true)
.build();
StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
assertTrue(cacheLoaderConfig instanceof OffheapStoreConfiguration);
OffheapStoreConfiguration config = (OffheapStoreConfiguration) cacheLoaderConfig;
assertEquals(true, config.compression());
EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);
cacheManager.defineConfiguration("testCache", cacheConfig);
cacheManager.start();
Cache<String, String> cache = cacheManager.getCache("testCache");
cache.put("hello", "there");
cache.stop();
cacheManager.stop();
}
示例7: testMessage
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
/**
* Simple messaging test.
*
* @throws IOException
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
@Test
public void testMessage() throws IOException, InterruptedException, ExecutionException, TimeoutException {
final int nodeNumber = 3;
// start test instance
EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder("node main", null).build();
this.cacheManager = cacheManager;
final Object monitor = new Object();
final Map<Address, String> messages = Maps.newConcurrentMap();
cacheManager.start();
cacheManager.getCache(TestConstants.CACHE_DEFAULT).addListener(new NodeMessageListener<String>() {
@Override
public void onMessage(Message<String> value) {
messages.put(value.getAddress(), value.getMessage());
synchronized (monitor) {
monitor.notify();
}
}
});
prepareCluster(nodeNumber, SimpleMessagingTask.class);
// wait for n (n=nodeNumber) messages
Callable<Boolean> test = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return messages.keySet().size() >= nodeNumber;
}
};
waitForEvent(monitor, test, 10, TimeUnit.SECONDS);
}
示例8: testMessage
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
/**
* Simple messaging test with other nodes' restart.
*
* @throws IOException
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
@Test
public void testMessage() throws IOException, InterruptedException, ExecutionException, TimeoutException {
final int nodeNumber = 3;
// start test instance
final EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder("node main", null).build();
this.cacheManager = cacheManager;
final Object monitor = new Object();
final Map<Address, String> messages = Maps.newConcurrentMap();
cacheManager.start();
cacheManager.getCache(TestConstants.CACHE_DEFAULT).addListener(new NodeMessageListener<String>() {
@Override
public void onMessage(Message<String> value) {
messages.put(value.getAddress(), value.getMessage());
synchronized (monitor) {
monitor.notify();
}
}
});
// SimpleMessagingTask: on connect, each node send a message
prepareCluster(nodeNumber, SimpleMessagingTask.class);
// wait for n (n=nodeNumber) messages
Callable<Boolean> testOne = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return messages.keySet().size() == nodeNumber;
}
};
// wait for messages from other nodes
waitForEvent(monitor, testOne, 10, TimeUnit.SECONDS);
// shutdown all nodes
shutdownProcesses(false);
// wait alone state (1 node)
Callable<Boolean> aloneTest = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return cacheManager.getMembers().size() == 1;
}
};
waitForEvent(monitor, aloneTest, 20, TimeUnit.SECONDS);
// start new nodes
prepareCluster(nodeNumber, SimpleMessagingTask.class);
// wait joining nodes
Callable<Boolean> allTest = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return cacheManager.getMembers().size() == 4;
}
};
waitForEvent(monitor, allTest, 20, TimeUnit.SECONDS);
// wait 6 messages (as new nodes use new addresses, new messages are added)
Callable<Boolean> testTwo = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return messages.keySet().size() == 6;
}
};
waitForEvent(monitor, testTwo, 10, TimeUnit.SECONDS);
}
示例9: testBatch
import org.infinispan.manager.EmbeddedCacheManager; //導入方法依賴的package包/類
/**
* Test {@link AdvancedCache#startBatch()} (to handle concurrent read / update).
* We lock to keys (A and B) and asks for second nodes (using message) to confirm that these keys cannot be locked
* concurrently.
* After keys' release, confirm that second node can now lock these keys.
*
* @throws IOException
* @throws InterruptedException
* @throws TimeoutException
* @throws ExecutionException
*/
@Test
public void testBatch() throws IOException, InterruptedException, TimeoutException, ExecutionException {
// start infinispan
final int nodeNumber = 1;
// start test instance
final EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder("node main", null).build();
this.cacheManager = cacheManager;
final Object monitor = new Object();
final Map<Address, String> messages = Maps.newConcurrentMap();
cacheManager.start();
cacheManager.getCache(TestConstants.CACHE_MESSAGE).addListener(new NodeMessageListener<String>() {
@Override
public void onMessage(Message<String> value) {
messages.put(value.getAddress(), value.getMessage());
synchronized (monitor) {
monitor.notify();
}
}
});
// initializes two keys A and B
cacheManager.getCache(TestConstants.CACHE_DEFAULT).put("A", "A");
cacheManager.getCache(TestConstants.CACHE_DEFAULT).put("B", "B");
// start another node that register a task that waits a message to lock A and B
prepareCluster(nodeNumber, LockTask.class);
// startBatch
AdvancedCache<Object, Object> cache = cacheManager.<Object, Object>getCache(TestConstants.CACHE_DEFAULT).getAdvancedCache();
cache.startBatch();
boolean successful = false;
final Address address = cacheManager.getAddress();
Callable<Boolean> test = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return ! address.equals(cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getAddress());
}
};
try {
// lock A and B
cache.lock("A", "B");
// send message -> second node cannot lock -> message TimeoutException
cacheManager.getCache(TestConstants.CACHE_MESSAGE).put(TestConstants.CACHE_KEY_MESSAGE_BUS, Message.from(address, LockTask.TRY_LOCK));
// must be set accordingly with lockAcquisitionTimeout
waitForEvent(monitor, test, 25, TimeUnit.SECONDS);
Assert.assertEquals(LockTask.TIMEOUT_EXCEPTION, cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getMessage());
successful = true;
} finally {
// stopBatch
cache.endBatch(successful);
}
// second node can lock
cacheManager.getCache(TestConstants.CACHE_MESSAGE).put(TestConstants.CACHE_KEY_MESSAGE_BUS, Message.from(address, LockTask.TRY_LOCK));
// must be set accordingly with lockAcquisitionTimeout
waitForEvent(monitor, test, 25, TimeUnit.SECONDS);
Assert.assertEquals(LockTask.LOCK_SUCCESS, cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getMessage());
}