private ClusteredQueryCommand(ClusteredQueryCommandType type, String cacheName) { super(ByteString.fromString(cacheName)); commandType = type; }
private ClusteredQueryCommand(CQCommandType commandType, String cacheName) { super(ByteString.fromString(cacheName)); this.commandType = commandType; }
/** * Clear all regions from this command factory. * * @param regions collection of regions to clear */ public void clearRegions(Collection<? extends InfinispanBaseRegion> regions) { regions.forEach(region -> allRegions.remove(ByteString.fromString(region.getCache().getName()))); }
/** * Add region so that commands can be cleared on shutdown. * * @param region instance to keep track of */ public void addRegion(InfinispanBaseRegion region) { allRegions.put(ByteString.fromString(region.getCache().getName()), region); }
public void testLargeString() throws Exception { StringBuilder sb = new StringBuilder(128); for (int i = 0; i < 128; i++) { sb.append("a"); } ByteString.fromString(sb.toString()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testTooLargeString() throws Exception { StringBuilder sb = new StringBuilder(256); for (int i = 0; i < 256; i++) { sb.append("a"); } ByteString.fromString(sb.toString()); } }
@Override protected ReplicableCommand createReplicableCommandForTest(Object arg) { return new CustomCacheRpcCommand(ByteString.fromString(TEST_CACHE), arg); } }
private ClusteredLockImpl createLock(String lockName) { ClusteredLockConfiguration configuration = getConfiguration(lockName); if (configuration == null) { throw new ClusteredLockException(String.format("Lock does %s not exist", lockName)); } ClusteredLockKey key = new ClusteredLockKey(ByteString.fromString(lockName)); cache.putIfAbsent(key, ClusteredLockValue.INITIAL_STATE); ClusteredLockImpl lock = new ClusteredLockImpl(lockName, key, cache, this); return lock; }
@Override public boolean defineLock(String name, ClusteredLockConfiguration configuration) { if (trace) { log.tracef("LOCK[%s] defineLock has been called %s", name, configuration); } // TODO: Configuration is not used because we don't support any other mode for now. For that : ISPN-8413 CacheHolder cacheHolder = extractCacheHolder(cacheHolderFuture); cache = cacheHolder.getClusteredLockCache(); ClusteredLockKey key = new ClusteredLockKey(ByteString.fromString(name)); ClusteredLockValue clusteredLockValue = cache.putIfAbsent(key, ClusteredLockValue.INITIAL_STATE); locks.putIfAbsent(name, new ClusteredLockImpl(name, key, cache, this)); return clusteredLockValue == null; }
@ManagedOperation( description = "Forces a release of the lock if such exist", displayName = "Release Clustered Lock", name = FORCE_RELEASE ) public boolean forceReleaseSync(String name) { if (trace) { log.tracef("LOCK[%s] forceRelease sync has been called", name); } ClusteredLockValue clusteredLockValue = cache.computeIfPresent(new ClusteredLockKey(ByteString.fromString(name)), (k, v) -> ClusteredLockValue.INITIAL_STATE); return clusteredLockValue != null && clusteredLockValue.getState() == ClusteredLockState.RELEASED; }
@ManagedOperation( description = "Returns true if the lock exists and is acquired", displayName = "Is Locked", name = IS_LOCKED ) public boolean isLockedSync(String name) { if (trace) { log.tracef("LOCK[%s] isLocked sync has been called", name); } ClusteredLockValue clusteredLockValue = cache.get(new ClusteredLockKey(ByteString.fromString(name))); return clusteredLockValue != null && clusteredLockValue.getState() == ClusteredLockState.ACQUIRED; }
public void testShortString() throws Exception { ByteString byteString = ByteString.fromString("abc"); ExposedByteArrayOutputStream outputStream = new ExposedByteArrayOutputStream(); try (ObjectOutput output = new ObjectOutputStream(outputStream)) { ByteString.writeObject(output, byteString); } ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.getRawBuffer()); try (ObjectInput input = new ObjectInputStream(inputStream)) { ByteString byteString2 = ByteString.readObject(input); assertEquals(byteString, byteString2); } }
@ManagedOperation( description = "Returns true if the lock is defined", displayName = "Is Lock Defined", name = IS_DEFINED ) @Override public boolean isDefined(String name) { if (trace) { log.tracef("LOCK[%s] isDefined has been called", name); } if (cache == null) { cache = extractCacheHolder(cacheHolderFuture).getClusteredLockCache(); } return cache.containsKey(new ClusteredLockKey(ByteString.fromString(name))); }
@Start private void start() { this.cacheName = ByteString.fromString(cache.getName()); this.setStatisticsEnabled(cacheConfiguration.jmxStatistics().enabled()); syncRpcOptions = rpcManager.getRpcOptionsBuilder(ResponseMode.SYNCHRONOUS_IGNORE_LEAVERS, DeliverOrder.NONE).build(); }
public PrepareCoordinator(AdvancedCache<byte[], byte[]> cache, XidImpl xid, boolean recoverable, long transactionTimeout) { this.xid = xid; this.recoverable = recoverable; this.transactionTimeout = transactionTimeout; this.cache = cache; ComponentRegistry registry = cache.getComponentRegistry(); this.transactionTable = registry.getComponent(TransactionTable.class); this.perCacheTxTable = registry.getComponent(PerCacheTxTable.class); this.globalTxTable = registry.getGlobalComponentRegistry().getComponent(GlobalTxTable.class); this.cacheXid = new CacheXid(ByteString.fromString(cache.getName()), xid); }
public void testEmptyString() throws Exception { ByteString byteString = ByteString.fromString(""); assertSame(ByteString.emptyString(), byteString); ExposedByteArrayOutputStream outputStream = new ExposedByteArrayOutputStream(); try (ObjectOutput output = new ObjectOutputStream(outputStream)) { ByteString.writeObject(output, byteString); } ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.getRawBuffer()); try (ObjectInput input = new ObjectInputStream(inputStream)) { ByteString byteString2 = ByteString.readObject(input); assertSame(ByteString.emptyString(), byteString2); } }
private boolean checkNotExists(DummyXid... xids) { for (DummyXid xid : xids) { CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid); if (globalTxTable(0).getState(cacheXid) != null) { return false; } } return true; }
private TxState getState(XidImpl xid) { return globalTxTable(0).getState(new CacheXid(fromString(cacheName()), xid)); }
public void testMarshallingCommandWithBigByteArrayKey() throws Exception { byte[] cacheKey = getBigByteArray(); ClusteredGetCommand command = new ClusteredGetCommand(new WrappedByteArray(cacheKey), ByteString.fromString("c"), 0, EnumUtil.EMPTY_BIT_SET); byte[] bytes = marshaller.objectToByteBuffer(command); ClusteredGetCommand readCommand = (ClusteredGetCommand) marshaller.objectFromByteBuffer(bytes); assertEquals(readCommand, command); }
private void assertStatus(boolean timeout, boolean recoverable, DummyXid... xids) { GlobalTxTable globalTxTable = globalTxTable(0); for (DummyXid xid : xids) { CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid); TxState state = globalTxTable.getState(cacheXid); assertEquals(recoverable, state.isRecoverable()); assertEquals(timeout, state.hasTimedOut(timeService.time())); } }