@Override public int nextSize(Object obj) { if (isTrace) log.tracef("Next predicted buffer size for object type '%s' will be %d", obj == null ? "Null" : obj.getClass().getName(), nextBufferSize); return nextBufferSize; }
public boolean isSafeClass(String className) { // Test for classes first (faster) boolean isClassAllowed = classes.contains(className); if (isClassAllowed) return true; boolean regexMatch = compiled.stream().anyMatch(p -> p.matcher(className).find()); if (regexMatch) return true; if (log.isTraceEnabled()) log.tracef("Class '%s' not in whitelist", className); return false; }
@Override public void resume(Transaction tx) throws InvalidTransactionException, IllegalStateException, SystemException { if (trace) { log.tracef("Resuming tx %s", tx); } associateTransaction(tx); }
/** * Unregister the MBean located under the given {@link ObjectName} * * @param objectName {@link ObjectName} where the MBean is registered * @param mBeanServer {@link MBeanServer} from which to unregister the MBean. * @throws Exception If unregistration could not be completed. */ public static void unregisterMBean(ObjectName objectName, MBeanServer mBeanServer) throws Exception { if (mBeanServer.isRegistered(objectName)) { SecurityActions.unregisterMBean(objectName, mBeanServer); log.tracef("Unregistered %s", objectName); } }
/** * Deletes directory recursively. * * @param directory Directory to be deleted */ public static void recursiveFileRemove(File directory) { if (directory.exists()) { log.tracef("Deleting file %s", directory); recursiveDelete(directory); } }
/** * Register a {@link Synchronization} callback with this transaction. * * @throws RollbackException If the transaction is marked for rollback only. * @throws IllegalStateException If the transaction is in a state where {@link Synchronization} callbacks cannot be * registered. This could be because the transaction is no longer active, or because it * is in the {@link Status#STATUS_PREPARED prepared state}. * @throws SystemException If the transaction service fails in an unexpected way. */ @Override public void registerSynchronization(Synchronization sync) throws RollbackException, IllegalStateException, SystemException { if (trace) { log.tracef("Transaction.registerSynchronization(%s) invoked in transaction with Xid=%s", sync, xid); } checkStatusBeforeRegister("synchronization"); if (trace) { log.tracef("Registering synchronization handler %s", sync); } synchronized (xidLock) { syncs.add(sync); } }
/** * Checks whether class name is matched by the class name white list regular expressions provided. * * @param className class to verify * @param whitelist list of regular expressions to match class name against * @return true if the class matched at least one of the regular expressions, * false otherwise */ public static boolean isSafeClass(String className, List<String> whitelist) { for (String whiteRegExp : whitelist) { Pattern whitePattern = Pattern.compile(whiteRegExp); Matcher whiteMatcher = whitePattern.matcher(className); if (whiteMatcher.find()) { if (log.isTraceEnabled()) log.tracef("Whitelist match: '%s'", className); return true; } } return false; }
@Override public Transaction suspend() throws SystemException { Transaction tx = getTransaction(); dissociateTransaction(); if (trace) { log.tracef("Suspending tx %s", tx); } return tx; }
private void notifyAfterCompletion(int status) { for (Synchronization s : getEnlistedSynchronization()) { if (trace) { log.tracef("Synchronization.afterCompletion() for %s", s); } try { s.afterCompletion(status); } catch (Throwable t) { log.afterCompletionFailed(s.toString(), t); } } syncs.clear(); }
/** * Marks a particular type as being marshallable or not being not marshallable. * * @param type Class to mark as serializable or non-serializable * @param isMarshallable Whether the type can be marshalled or not. */ public void markMarshallable(Class<?> type, boolean isMarshallable) { MarshallingType marshallType = typeHints.get(type); if (marshallableUpdateRequired(isMarshallable, marshallType)) { boolean replaced = typeHints.replace(type, marshallType, new MarshallingType( Boolean.valueOf(isMarshallable), marshallType.sizePredictor)); if (replaced && trace) { log.tracef("Replacing '%s' type to be marshallable=%b", type.getName(), isMarshallable); } } else if (marshallType == null) { if (trace) { log.tracef("Cache '%s' type to be marshallable=%b", type.getName(), isMarshallable); } typeHints.put(type, new MarshallingType( Boolean.valueOf(isMarshallable), new AdaptiveBufferSizePredictor())); } }
/** * Get the serialized form size predictor for a particular type. * * @param type Marshallable type for which serialized form size will be predicted * @return an instance of {@link BufferSizePredictor} */ public BufferSizePredictor getBufferSizePredictor(Class<?> type) { MarshallingType marshallingType = typeHints.get(type); if (marshallingType == null) { // Initialise with isMarshallable to null, meaning it's unknown marshallingType = new MarshallingType(null, new AdaptiveBufferSizePredictor()); MarshallingType prev = typeHints.putIfAbsent(type, marshallingType); if (prev != null) { marshallingType = prev; } else { if (trace) { log.tracef("Cache a buffer size predictor for '%s' assuming " + "its serializability is unknown", type.getName()); } } } return marshallingType.sizePredictor; }
/** * Mark the transaction so that the only possible outcome is a rollback. * * @throws IllegalStateException If the transaction is not in an active state. * @throws SystemException If the transaction service fails in an unexpected way. */ @Override public void setRollbackOnly() throws IllegalStateException, SystemException { if (trace) { log.tracef("Transaction.setRollbackOnly() invoked in transaction with Xid=%s", xid); } if (isDone()) { throw new IllegalStateException("Transaction is done. Cannot change status"); } markRollbackOnly(new RollbackException("Transaction marked as rollback only.")); }
/** * Register the given dynamic JMX MBean. * * @param mbean Dynamic MBean to register * @param objectName {@link ObjectName} under which to register the MBean. * @param mBeanServer {@link MBeanServer} where to store the MBean. * @throws Exception If registration could not be completed. */ public static void registerMBean(Object mbean, ObjectName objectName, MBeanServer mBeanServer) throws Exception { if (!mBeanServer.isRegistered(objectName)) { try { SecurityActions.registerMBean(mbean, objectName, mBeanServer); log.tracef("Registered %s under %s", mbean, objectName); } catch (InstanceAlreadyExistsException e) { //this might happen if multiple instances are trying to concurrently register same objectName log.couldNotRegisterObjectName(objectName, e); } } else { log.debugf("Object name %s already registered", objectName); } }
private void notifyBeforeCompletion() { for (Synchronization s : getEnlistedSynchronization()) { if (trace) { log.tracef("Synchronization.beforeCompletion() for %s", s); } try { s.beforeCompletion(); } catch (Throwable t) { markRollbackOnly( newRollbackException(format("Synchronization.beforeCompletion() for %s wants to rollback.", s), t)); log.beforeCompletionFailed(s.toString(), t); } } }
@Override final public ObjectInput startObjectInput(final InputStream is, final boolean isReentrant) throws IOException { PerThreadInstanceHolder instanceHolder = getPerThreadInstanceHolder(); Unmarshaller unmarshaller = instanceHolder.getUnmarshaller(); if (trace) log.tracef("Start unmarshaller after retrieving marshaller from %s", isReentrant ? "factory" : "thread local"); unmarshaller.start(Marshalling.createByteInput(is)); return unmarshaller; }
private void endResources() { for (XAResource resource : getEnlistedResources()) { if (trace) { log.tracef("XAResource.end() for %s", resource); } try { resource.end(xid, XAResource.TMSUCCESS); } catch (XAException e) { markRollbackOnly(newRollbackException(format("XaResource.end() for %s wants to rollback.", resource), e)); log.xaResourceEndFailed(resource.toString(), e); } catch (Throwable t) { markRollbackOnly(newRollbackException( format("Unexpected error in XaResource.end() for %s. Marked as rollback", resource), t)); log.xaResourceEndFailed(resource.toString(), t); } } }
public String fromStoredKey(RemoteCache cache, String key) throws IOException, InterruptedException, ClassNotFoundException { Object o = cache.getRemoteCacheManager().getMarshaller().objectFromByteBuffer(Base64.getDecoder().decode(key.substring(2))); log.tracef("Key in DB=%s > %s", key, o); return (String)o; }
@Test public void testDataRetrievableViaRocksDbApi() throws Exception { controller.start(CONTAINER); RemoteInfinispanCacheManager managerJmx = server.getCacheManager("local"); RemoteInfinispanCache cacheJmx = managerJmx.getCache("testcache"); RemoteCache<String, String> cache = createManager().getCache(); cache.clear(); assertEquals(0, cacheJmx.getNumberOfEntries()); cache.put("key1", "1"); assertEquals("1", cache.get("key1")); System.out.println("Stored via Hot Rod:"); assertTrue(dataDir.exists()); assertTrue(dataDir.isDirectory()); assertTrue(expiredDir.exists()); assertTrue(expiredDir.isDirectory()); controller.stop(CONTAINER); RocksDB db = RocksDB.open(new Options(), dataDir.getAbsolutePath()); log.tracef("RocksDB file " + dataDir.getAbsolutePath() + " contents:"); for(RocksIterator i = db.newIterator(); i.isValid(); i.next()) { log.tracef("key \"" + Hex.encodeHexString(i.key()) + "\": value \"" + Hex.encodeHexString(i.value()) + "\""); assertNotNull(i.value()); } }
@Test public void testExpTimeAbsoluteFuture() throws Exception { long now = mc.getServerTime(); log.tracef("server time: " + now); mc.writeln("set " + KEY_A + " 0 " + (now + 2) + " 1"); mc.writeln("A"); mc.flush(); assertEquals("STORED", mc.readln()); assertEquals("A", mc.get(KEY_A)); sleepForSecs(2); assertNull(mc.get(KEY_A)); }
@Test public void testDataSurvivesRestart() { controller.start(CONTAINER); RemoteInfinispanCacheManager managerJmx = server.getCacheManager("local"); RemoteInfinispanCache cacheJmx = managerJmx.getCache("testcache"); RemoteCache<String, String> cache = createManager().getCache(); cache.clear(); assertEquals(0, cacheJmx.getNumberOfEntries()); cache.put("key1", "1"); cache.put("key2", "2"); cache.put("key3", "3"); assertEquals("1", cache.get("key1")); assertEquals("2", cache.get("key2")); assertEquals("3", cache.get("key3")); log.tracef("Stored via Hot Rod:"); assertTrue(dataDir.exists()); assertTrue(dataDir.isDirectory()); assertTrue(expiredDir.exists()); assertTrue(expiredDir.isDirectory()); controller.stop(CONTAINER); controller.start(CONTAINER); assertEquals("1", cache.get("key1")); assertEquals("2", cache.get("key2")); assertEquals("3", cache.get("key3")); controller.stop(CONTAINER); }