repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MutableRolePermissionMapper.java
|
MutableRolePermissionMapper mapper = (MutableRolePermissionMapper) cacheManager.getCacheManagerConfiguration().security().authorization().rolePermissionMapper();
mapper.addRole(Role.newRole("myroleone", true, AuthorizationPermission.ALL_WRITE, AuthorizationPermission.LISTEN));
mapper.addRole(Role.newRole("myroletwo", true, AuthorizationPermission.READ, AuthorizationPermission.WRITE));
| 388
| 96.25
| 161
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/InjectDependencies.java
|
@Inject
public void injectDependencies(DataContainer container, Configuration configuration) {
this.container = container;
this.configuration = configuration;
}
@DefaultFactoryFor
public class DataContainerFactory extends AbstractNamedCacheComponentFactory {
| 266
| 28.666667
| 86
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/IndexWriterConfig.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.indexing()
.storage(FILESYSTEM)
.path("/temp")
.writer()
.commitInterval(2000)
.setLowLevelTrace(false)
.maxBufferedEntries(32)
.queueCount(1)
.queueSize(10000)
.ramBufferSize(400)
.threadPoolSize(2)
.merge()
.calibrateByDeletes(true)
.factor(3).
.maxDocs(2000)
.minSize(10)
.maxSize(20);
.addIndexedEntities(Book.class);
| 479
| 23
| 58
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigurationBuilderClientBuilder.java
|
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder
.addServer()
.host("127.0.0.1")
.port(hotrodServer.getPort())
.security()
.ssl()
.enabled(sslClient)
.sniHostName("hotrod-1") // SNI Host Name
.trustStoreFileName("truststore.jks")
.trustStorePassword("secret".toCharArray());
remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
| 450
| 33.692308
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodCreatePerCache.java
|
File file = new File("path/to/infinispan.xml")
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.remoteCache("another-cache")
.configuration("<distributed-cache name=\"another-cache\"/>");
builder.remoteCache("my.other.cache")
.configurationURI(file.toURI());
| 291
| 40.714286
| 69
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodPlain.java
|
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("PLAIN")
.username("myuser")
.password("qwer1234!");
| 330
| 32.1
| 64
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ClusteredLock.java
|
@Experimental
public interface ClusteredLock {
CompletableFuture<Void> lock();
CompletableFuture<Boolean> tryLock();
CompletableFuture<Boolean> tryLock(long time, TimeUnit unit);
CompletableFuture<Void> unlock();
CompletableFuture<Boolean> isLocked();
CompletableFuture<Boolean> isLockedByMe();
}
| 321
| 19.125
| 64
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodForceReturn.java
|
cache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey", "newValue")
| 65
| 32
| 64
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/AdvancedExternalizer.java
|
import org.infinispan.marshall.AdvancedExternalizer;
public class Person {
final String name;
final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public static class PersonExternalizer implements AdvancedExternalizer<Person> {
@Override
public void writeObject(ObjectOutput output, Person person)
throws IOException {
output.writeObject(person.name);
output.writeInt(person.age);
}
@Override
public Person readObject(ObjectInput input)
throws IOException, ClassNotFoundException {
return new Person((String) input.readObject(), input.readInt());
}
@Override
public Set<Class<? extends Person>> getTypeClasses() {
return Util.<Class<? extends Person>>asSet(Person.class);
}
@Override
public Integer getId() {
return 2345;
}
}
}
| 942
| 23.815789
| 83
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/OverrideDefaultCacheConfig.java
|
public class Config {
// By default CDI adds the @Default qualifier if no other qualifier is provided.
@Produces
public Configuration defaultEmbeddedCacheConfiguration() {
return new ConfigurationBuilder()
.memory()
.size(100)
.build();
}
}
| 330
| 26.583333
| 84
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MultiMapCacheEmbedded.java
|
// create or obtain your EmbeddedCacheManager
EmbeddedCacheManager cm = ... ;
// create or obtain a MultimapCacheManager passing the EmbeddedCacheManager
MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm);
// define the configuration for the multimap cache
multimapCacheManager.defineConfiguration(multimapCacheName, c.build());
// get the multimap cache
multimapCache = multimapCacheManager.get(multimapCacheName);
| 457
| 37.166667
| 89
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigEvictionMemory.java
|
Configuration c = new ConfigurationBuilder()
.memory()
.storageType(StorageType.BINARY)
.evictionType(EvictionType.MEMORY)
.size(1_000_000_000)
.build();
| 229
| 31.857143
| 49
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigDistributedCacheMode.java
|
cacheManager.defineConfiguration("dist", new ConfigurationBuilder()
.clustering()
.cacheMode(CacheMode.DIST_SYNC)
.hash().numOwners(2)
.build()
);
| 171
| 23.571429
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MaxSizeMemory.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.encoding().mediaType("application/x-protostream")
.memory()
.maxSize("1.5GB")
.whenFull(EvictionStrategy.REMOVE);
| 206
| 33.5
| 58
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ExampleApplicationInjectCache.java
|
public class ExampleApplication {
@Resource(lookup = "java:jboss/datagrid-infinispan/container/infinispan_container")
CacheContainer container;
@Resource(lookup = "java:jboss/datagrid-infinispan/container/infinispan_container/cache/namedCache")
Cache cache;
}
| 277
| 33.75
| 104
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CacheMultipleKeyValuePairs.java
|
Cache<String, User> usersCache = cacheManager.getCache("myCache");
usersCache.put("raytsang", new User());
Cache<Integer, Teacher> teachersCache = cacheManager.getCache("myCache");
teachersCache.put(1, new Teacher());
| 218
| 42.8
| 73
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/GlobalJmxStatistics.java
|
GlobalConfigurationBuilder globalConfigurationBuilder = ...
globalConfigurationBuilder.jmx().enable();
| 103
| 33.666667
| 59
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ListenerFuture.java
|
FutureListener futureListener = new FutureListener() {
public void futureDone(Future future) {
try {
future.get();
} catch (Exception e) {
// Future did not complete successfully
System.out.println("Help!");
}
}
};
cache.putAsync("key", "value").attachListener(futureListener);
| 336
| 23.071429
| 62
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CacheMetricsRegistrar.java
|
@Autowire
CacheMetricsRegistrar cacheMetricsRegistrar;
@Autowire
CacheManager cacheManager;
...
cacheMetricsRegistrar.bindCacheToRegistry(cacheManager.getCache("my-cache"));
| 176
| 18.666667
| 77
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigurationCustomizerBean.java
|
@Bean
public InfinispanGlobalConfigurationCustomizer globalCustomizer() {
return builder -> builder.transport().clusterName(CLUSTER_NAME);
}
@Bean
public InfinispanConfigurationCustomizer configurationCustomizer() {
return builder -> builder.memory().evictionType(EvictionType.COUNT);
}
| 294
| 28.5
| 71
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ReadOnlyMapFindMetaParam.java
|
class MetaEntryVersion<T> implements MetaParam.Writable<EntryVersion<T>> {
...
public static <T> T type() { return (T) MetaEntryVersion.class; }
...
}
ReadOnlyMap<String, String> readOnlyMap = ...
CompletableFuture<String> readFuture = readOnlyMap.eval("key1", view -> {
// The caller wants guarantees that the metadata parameter for version is numeric
// e.g. to query the actual version information
Optional<MetaEntryVersion<Long>> version = view.findMetaParam(MetaEntryVersion.type());
return view.get();
});
| 535
| 34.733333
| 90
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CreateCacheMutableConfiguration.java
|
Cache<String, String> cache = cacheManager.createCache("namedCache",
new MutableConfiguration<String, String>().setStoreByValue(false));
| 143
| 47
| 73
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/GetAdvancedCacheWithFlagsSkipRemoteLookup.java
|
Cache cache = ...
cache.getAdvancedCache()
.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_CACHE_LOAD)
.put("local", "only")
| 129
| 25
| 60
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/EncodeMediaTypeOverride.java
|
DefaultCacheManager cacheManager = new DefaultCacheManager();
// Encode keys and values as Protobuf
ConfigurationBuilder cfg = new ConfigurationBuilder();
cfg.encoding().key().mediaType("application/x-protostream");
cfg.encoding().value().mediaType("application/x-protostream");
cacheManager.defineConfiguration("mycache", cfg.build());
Cache<Integer, Person> cache = cacheManager.getCache("mycache");
cache.put(1, new Person("John","Doe"));
// Use Protobuf for keys and JSON for values
Cache<Integer, byte[]> jsonValuesCache = (Cache<Integer, byte[]>) cache.getAdvancedCache().withMediaType("application/x-protostream", "application/json");
byte[] json = jsonValuesCache.get(1);
| 686
| 37.166667
| 154
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ExternalizerRegisterMultiple.java
|
builder.serialization()
.addAdvancedExternalizer(new Person.PersonExternalizer(),
new Address.AddressExternalizer());
| 149
| 36.5
| 63
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/RetrieveClusteredLockManager.java
|
// create or obtain your EmbeddedCacheManager
EmbeddedCacheManager manager = ...;
// retrieve the ClusteredLockManager
ClusteredLockManager clusteredLockManager = EmbeddedClusteredLockManagerFactory.from(manager);
| 215
| 35
| 94
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/AdvancedExternalizerAddBookExternalizer.java
|
GlobalConfigurationBuilder builder = ...
builder.serialization().addAdvancedExternalizer(new Book.BookExternalizer());
| 119
| 39
| 77
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/JmxGlobalConfigurationBuilder.java
|
GlobalConfiguration global = GlobalConfigurationBuilder.defaultClusteredBuilder()
.jmx().enable()
.domain("org.mydomain");
| 129
| 31.5
| 81
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/EmbeddedConflictManager.java
|
EmbeddedCacheManager manager = new DefaultCacheManager("example-config.xml");
Cache<Integer, String> cache = manager.getCache("testCache");
ConflictManager<Integer, String> crm = ConflictManagerFactory.get(cache.getAdvancedCache());
// Get all versions of a key
Map<Address, InternalCacheValue<String>> versions = crm.getAllVersions(1);
// Process conflicts stream and perform some operation on the cache
Stream<Map<Address, CacheEntry<Integer, String>>> conflicts = crm.getConflicts();
conflicts.forEach(map -> {
CacheEntry<Integer, String> entry = map.values().iterator().next();
Object conflictKey = entry.getKey();
cache.remove(conflictKey);
});
// Detect and then resolve conflicts using the configured EntryMergePolicy
crm.resolveConflicts();
// Detect and then resolve conflicts using the passed EntryMergePolicy instance
crm.resolveConflicts((preferredEntry, otherEntries) -> preferredEntry);
| 914
| 42.571429
| 92
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/PersonId.java
|
// Id of the person to look up, provided by the application
PersonId id = ...;
// Get a reference to the cache where person instances will be stored
Cache<PersonId, Person> cache = ...;
// First, check whether the cache contains the person instance
// associated with with the given id
Person cachedPerson = cache.get(id);
if (cachedPerson == null) {
// The person is not cached yet, so query the data store with the id
Person person = dataStore.lookup(id);
// Cache the person along with the id so that future requests can
// retrieve it from memory rather than going to the data store
cache.putForExternalRead(id, person);
} else {
// The person was found in the cache, so return it to the application
return cachedPerson;
}
| 752
| 33.227273
| 72
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/JmxMBeanServerLookup.java
|
GlobalConfiguration global = GlobalConfigurationBuilder.defaultClusteredBuilder()
.jmx().enable()
.domain("org.mydomain")
.mBeanServerLookup(new com.acme.MyMBeanServerLookup());
| 187
| 36.6
| 81
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/SingleNode.java
|
EmbeddedCacheManager manager = ...;
manager.executor().singleNodeSubmission().submit(...)
| 90
| 29.333333
| 53
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterListener.java
|
public interface CounterListener {
void onUpdate(CounterEvent entry);
}
| 75
| 18
| 37
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/RegisteringContinuousQuery.java
|
import org.infinispan.query.api.continuous.ContinuousQuery;
import org.infinispan.query.api.continuous.ContinuousQueryListener;
import org.infinispan.query.Search;
import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.Query;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
[...]
// We have a cache of Person objects.
Cache<Integer, Person> cache = ...
// Create a ContinuousQuery instance on the cache.
ContinuousQuery<Integer, Person> continuousQuery = Search.getContinuousQuery(cache);
// Define a query.
// In this example, we search for Person instances under 21 years of age.
QueryFactory queryFactory = Search.getQueryFactory(cache);
Query query = queryFactory.create("FROM Person p WHERE p.age < 21");
final Map<Integer, Person> matches = new ConcurrentHashMap<Integer, Person>();
// Define the ContinuousQueryListener.
ContinuousQueryListener<Integer, Person> listener = new ContinuousQueryListener<Integer, Person>() {
@Override
public void resultJoining(Integer key, Person value) {
matches.put(key, value);
}
@Override
public void resultUpdated(Integer key, Person value) {
// We do not process this event.
}
@Override
public void resultLeaving(Integer key) {
matches.remove(key);
}
};
// Add the listener and the query.
continuousQuery.addContinuousQueryListener(query, listener);
[...]
// Remove the listener to stop receiving notifications.
continuousQuery.removeContinuousQueryListener(listener);
| 1,529
| 29.6
| 100
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CustomMergePolicyEntryMerge.java
|
public class CustomMergePolicy implements EntryMergePolicy<String, String> {
@Override
public CacheEntry<String, String> merge(CacheEntry<String, String> preferredEntry, List<CacheEntry<String, String>> otherEntries) {
// Decide which entry resolves the conflict
return the_solved_CacheEntry;
}
| 318
| 34.444444
| 134
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodDefaultCluster.java
|
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServers("hostA1:11222; hostA2:11222")
.addCluster("siteB")
.addClusterNodes("hostB1:11222; hostB2:11223");
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
| 304
| 49.833333
| 86
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodDigest.java
|
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("DIGEST-MD5")
.username("myuser")
.password("qwer1234!");
| 335
| 32.6
| 64
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigurationBuilderCacheEncoding.java
|
//Create cache configuration that encodes keys and values as ProtoStream
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC)
.encoding().key().mediaType("application/x-protostream")
.encoding().value().mediaType("application/x-protostream");
| 315
| 51.666667
| 72
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterStrongMethod.java
|
default CompletableFuture<Long> incrementAndGet() {
return addAndGet(1L);
}
default CompletableFuture<Long> decrementAndGet() {
return addAndGet(-1L);
}
CompletableFuture<Long> addAndGet(long delta);
CompletableFuture<Boolean> compareAndSet(long expect, long update);
CompletableFuture<Long> compareAndSwap(long expect, long update);
| 344
| 23.642857
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/GridFileSystemReadExample.java
|
InputStream in=in.getInput("/grid-movies/dvd-image.iso");
OutputStream out=new FileOutputStream("/tmp/my-movies/dvd-image.iso");
byte[] buffer=new byte[200000];
int len;
while((len=in.read(buffer, 0, buffer.length)) != -1) out.write(buffer, 0, len);
in.close();
out.close();
| 275
| 33.5
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/SameRack.java
|
EmbeddedCacheManager manager = ...;
manager.executor().filterTargets(ClusterExecutionPolicy.SAME_RACK).submit(...)
| 115
| 37.666667
| 78
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/PersistenceJdbcStringBased.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class)
.dialect(DatabaseType.H2)
.table()
.dropOnExit(true)
.createOnStart(true)
.tableNamePrefix("ISPN_STRING_TABLE")
.idColumnName("ID_COLUMN").idColumnType("VARCHAR(255)")
.dataColumnName("DATA_COLUMN").dataColumnType("BINARY")
.timestampColumnName("TIMESTAMP_COLUMN").timestampColumnType("BIGINT")
.segmentColumnName("SEGMENT_COLUMN").segmentColumnType("INT")
.connectionPool()
.connectionUrl("jdbc:h2:mem:infinispan")
.username("sa")
.password("changeme")
.driverClass("org.h2.Driver");
| 740
| 42.588235
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ExternalizerRegisterPerson.java
|
GlobalConfigurationBuilder builder = ...
builder.serialization()
.addAdvancedExternalizer(new Person.PersonExternalizer());
| 127
| 31
| 61
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/InfinispanContainerCredentials.java
|
InfinispanContainer container = new InfinispanContainer();
container.withUser("admin").withPassword("secret");
container.start();
| 130
| 31.75
| 58
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ListenerMyCluster.java
|
@Listener (clustered = true)
public class MyClusterListener { .... }
| 69
| 22.333333
| 39
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CachePutWithExpiration.java
|
//Lifespan of 5 seconds.
//Maximum idle time of 1 second.
cache.put("hello", "world", 5, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
//Lifespan is disabled with a value of -1.
//Maximum idle time of 1 second.
cache.put("hello", "world", -1, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
| 278
| 33.875
| 71
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodUri.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.uri("hotrod://username:changeme@127.0.0.1:11222,192.0.2.0:11222?auth_realm=default&sasl_mechanism=SCRAM-SHA-512");
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
| 257
| 63.5
| 122
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/PersistenceJdbcConnectionSimple.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.persistence()
.simpleConnection()
.connectionUrl("jdbc:h2://localhost")
.driverClass("org.h2.Driver")
.username("admin")
.password("changeme");
| 254
| 30.875
| 58
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterGetStrongUnbounded.java
|
StrongCounter counter = counterManager.getStrongCounter("unbounded_counter");
// incrementing the counter
System.out.println("new value is " + counter.incrementAndGet().get());
// decrement the counter's value by 100 using the functional API
counter.addAndGet(-100).thenApply(v -> {
System.out.println("new value is " + v);
return null;
}).get();
// alternative, you can do some work while the counter is updated
CompletableFuture<Long> f = counter.addAndGet(10);
// ... do some work ...
System.out.println("new value is " + f.get());
// and then, check the current value
System.out.println("current value is " + counter.getValue().get());
// finally, reset to initial value
counter.reset().get();
System.out.println("current value is " + counter.getValue().get());
// or set to a new value if zero
System.out.println("compare and set succeeded? " + counter.compareAndSet(0, 1));
| 892
| 33.346154
| 80
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigureTransport.java
|
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().transport()
.defaultTransport()
.clusterName("prod-cluster")
.addProperty("configurationFile", "prod-jgroups-tcp.xml") <1>
.build();
| 233
| 38
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/WriteOnlyMapSerializable.java
|
import org.infinispan.functional.EntryView.*;
import org.infinispan.functional.FunctionalMap.*;
WriteOnlyMap<String, String> writeOnlyMap = ...
// Force a function to be Serializable
Consumer<WriteEntryView<String>> function =
(Consumer<WriteEntryView<String>> & Serializable) wv -> wv.set("one");
CompletableFuture<Void> writeFuture = writeOnlyMap.eval("key1", function);
| 379
| 33.545455
| 74
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/LocalSite.java
|
GlobalConfigurationBuilder lonGc = GlobalConfigurationBuilder.defaultClusteredBuilder();
lonGc.site().localSite("LON");
| 120
| 39.333333
| 88
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/WriteOnlyMapRemoveAll.java
|
WriteOnlyMap<String, String> writeOnlyMap = ...
CompletableFuture<Void> removeAllFuture = writeOnlyMap.evalAll(WriteEntryView::remove);
removeAllFuture.thenAccept(x -> "All entries removed");
| 193
| 37.8
| 87
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ManualEviction.java
|
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.memory().maxCount(500).whenFull(EvictionStrategy.MANUAL);
| 125
| 41
| 65
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ScriptExecute.java
|
RemoteCache<String, Integer> cache = cacheManager.getCache();
// Create parameters for script execution.
Map<String, Object> params = new HashMap<>();
params.put("multiplicand", 10);
params.put("multiplier", 20);
// Run the script with the parameters.
Object result = cache.execute("multiplication.js", params);
| 312
| 38.125
| 61
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MultiMapCachePut.java
|
MultimapCache<String, String> multimapCache = ...;
multimapCache.put("girlNames", "marie")
.thenCompose(r1 -> multimapCache.put("girlNames", "oihana"))
.thenCompose(r3 -> multimapCache.get("girlNames"))
.thenAccept(names -> {
if(names.contains("marie"))
System.out.println("Marie is a girl name");
if(names.contains("oihana"))
System.out.println("Oihana is a girl name");
});
| 554
| 41.692308
| 74
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MultiMapCache.java
|
public interface MultimapCache<K, V> {
CompletableFuture<Optional<CacheEntry<K, Collection<V>>>> getEntry(K key);
CompletableFuture<Void> remove(SerializablePredicate<? super V> p);
CompletableFuture<Void> put(K key, V value);
CompletableFuture<Collection<V>> get(K key);
CompletableFuture<Boolean> remove(K key);
CompletableFuture<Boolean> remove(K key, V value);
CompletableFuture<Void> remove(Predicate<? super V> p);
CompletableFuture<Boolean> containsKey(K key);
CompletableFuture<Boolean> containsValue(V value);
CompletableFuture<Boolean> containsEntry(K key, V value);
CompletableFuture<Long> size();
boolean supportsDuplicates();
}
| 690
| 23.678571
| 77
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CustomInterceptors.java
|
CacheManager cm = getCacheManager();//magic
Cache aCache = cm.getCache("aName");
AdvancedCache advCache = aCache.getAdvancedCache();
| 133
| 32.5
| 51
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ReadWriteMapMarshallableFunctions.java
|
import org.infinispan.functional.EntryView.*;
import org.infinispan.functional.FunctionalMap.*;
import org.infinispan.commons.marshall.MarshallableFunctions;
ReadWriteMap<String, String> readWriteMap = ...
CompletableFuture<Boolean> future = readWriteMap.eval("key1,
MarshallableFunctions.setValueIfAbsentReturnBoolean());
future.thenAccept(stored -> System.out.printf("Value was put? %s%n", stored));
| 407
| 39.8
| 78
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/GlobalPersistentLocation.java
|
new GlobalConfigurationBuilder().globalState()
.enable()
.persistentLocation("global/state", "my.data");
| 169
| 41.5
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/Library.java
|
import java.util.ArrayList;
import java.util.List;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
public class Library {
public static class Book {
@ProtoField(number = 1)
final String title;
@ProtoField(number = 2)
final String description;
@ProtoField(number = 3, defaultValue = "0")
final int publicationYear;
@ProtoField(number = 4, collectionImplementation = ArrayList.class)
final List<Author> authors;
@ProtoFactory
Book(String title, String description, int publicationYear, List<Author> authors) {
this.title = title;
this.description = description;
this.publicationYear = publicationYear;
this.authors = authors;
}
}
public static class Author {
@ProtoField(number = 1)
final String name;
@ProtoField(number = 2)
final String surname;
@ProtoFactory
Author(String name, String surname) {
this.name = name;
this.surname = surname;
}
}
}
| 1,098
| 24.55814
| 89
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigureTransportDefault.java
|
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().transport()
.defaultTransport()
.clusterName("qa-cluster")
//Uses the default-jgroups-udp.xml stack for cluster transport.
.addProperty("configurationFile", "default-jgroups-udp.xml")
.build();
| 302
| 42.285714
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/MBeanServerLookup.java
|
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.jmx()
.cacheManagerName("SalesCacheManager")
.mBeanServerLookup(new JBossMBeanServerLookup())
.build();
| 185
| 30
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/AutowiredEmbeddedCacheManager.java
|
private final EmbeddedCacheManager cacheManager;
@Autowired
public YourClassName(EmbeddedCacheManager cacheManager) {
this.cacheManager = cacheManager;
}
| 159
| 21.857143
| 57
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ReadOnlyMap.java
|
import org.infinispan.functional.EntryView.ReadEntryView;
import org.infinispan.functional.FunctionalMap.ReadOnlyMap;
ReadOnlyMap<String, String> readOnlyMap = ...
CompletableFuture<Optional<String>> readFuture = readOnlyMap.eval("key1", ReadEntryView::find);
readFuture.thenAccept(System.out::println);
| 305
| 42.714286
| 95
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ListenerMyRetry.java
|
@Listener
public class MyRetryListener {
@CacheEntryModified
public void entryModified(CacheEntryModifiedEvent event) {
if (event.isCommandRetried()) {
// Do something
}
}
}
| 194
| 18.5
| 60
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigExternalizers.java
|
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.serialization()
.addAdvancedExternalizer(998, new PersonExternalizer())
.addAdvancedExternalizer(999, new AddressExternalizer())
.build();
| 220
| 35.833333
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/TransactionDoubleCheckedLocking.java
|
Cache cache = ...
TransactionManager tm = ...
tm.begin();
try {
Integer v1 = cache.get(k);
// Increment the value
Integer v2 = cache.put(k, v1 + 1);
if (Objects.equals(v1, v2) {
// success
} else {
// retry
}
} finally {
tm.commit();
}
| 269
| 14.882353
| 37
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ListenerLoggingListener.java
|
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.*;
import org.infinispan.notifications.cachelistener.event.*;
import org.jboss.logging.Logger;
@Listener
public class LoggingListener {
private BasicLogger log = BasicLogFactory.getLog(LoggingListener.class);
@CacheEntryCreated
public void observeAdd(CacheEntryCreatedEvent<String, String> event) {
if (event.isPre())
return;
log.infof("Cache entry %s = %s added in cache %s", event.getKey(), event.getValue(), event.getCache());
}
@CacheEntryModified
public void observeUpdate(CacheEntryModifiedEvent<String, String> event) {
if (event.isPre())
return;
log.infof("Cache entry %s = %s modified in cache %s", event.getKey(), event.getValue(), event.getCache());
}
@CacheEntryRemoved
public void observeRemove(CacheEntryRemovedEvent<String, String> event) {
if (event.isPre())
return;
log.infof("Cache entry %s removed in cache %s", event.getKey(), event.getCache());
}
}
| 1,075
| 32.625
| 112
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/OverrideEmbeddedCacheManagerTransport.java
|
...
package org.infinispan.configuration.global.GlobalConfigurationBuilder;
@Produces
@ApplicationScoped
public EmbeddedCacheManager defaultClusteredCacheManager() {
return new DefaultCacheManager(
new GlobalConfigurationBuilder().transport().defaultTransport().build(),
new ConfigurationBuilder().memory().size(7).build()
);
}
| 353
| 28.5
| 80
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/WriteOnlyMapStoreKeys.java
|
WriteOnlyMap<String, String> writeOnlyMap = ...
Map<K, String> data = new HashMap<>();
data.put("key1", "value1");
data.put("key2", "value2");
CompletableFuture<Void> writerAllFuture = writeOnlyMap.evalMany(data, (v, view) -> view.set(v));
writerAllFuture.thenAccept(x -> "Write completed");
| 293
| 35.75
| 96
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterWeakMethod.java
|
default CompletableFuture<Void> increment() {
return add(1L);
}
default CompletableFuture<Void> decrement() {
return add(-1L);
}
CompletableFuture<Void> add(long delta);
| 178
| 16.9
| 45
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/AdvancedCacheAvailibilityMode.java
|
AdvancedCache ac = cache.getAdvancedCache();
// Retrieve cache availability
boolean available = ac.getAvailability() == AvailabilityMode.AVAILABLE;
// Make the cache available
if (!available) {
ac.setAvailability(AvailabilityMode.AVAILABLE);
}
| 247
| 30
| 71
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/Predicate.java
|
EmbeddedCacheManager manager = ...;
// Just filter
manager.executor().filterTargets(a -> a.equals(..)).submit(...)
// Filter only those in the desired topology
manager.executor().filterTargets(ClusterExecutionPolicy.SAME_SITE, a -> a.equals(..)).submit(...)
| 258
| 42.166667
| 97
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/StorageTypeBinary.java
|
ConfigurationBuilder builder = ...
builder.memory().storageType(StorageType.BINARY);
| 85
| 27.666667
| 49
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ListenerMyAsync.java
|
@Listener (sync = false)
public class MyAsyncListener {
@CacheEntryCreated
void listen(CacheEntryCreatedEvent event) { }
}
| 129
| 20.666667
| 48
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ProtoAdapter.java
|
import java.util.UUID;
import org.infinispan.protostream.annotations.ProtoAdapter;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
import org.infinispan.protostream.descriptors.Type;
/**
* Human readable UUID adapter for UUID marshalling
*/
@ProtoAdapter(UUID.class)
public class UUIDAdapter {
@ProtoFactory
UUID create(String stringUUID) {
return UUID.fromString(stringUUID);
}
@ProtoField(1)
String getStringUUID(UUID uuid) {
return uuid.toString();
}
}
| 552
| 22.041667
| 59
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterGetStrongBounded.java
|
StrongCounter counter = counterManager.getStrongCounter("bounded_counter");
// incrementing the counter
try {
System.out.println("new value is " + counter.addAndGet(100).get());
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof CounterOutOfBoundsException) {
if (((CounterOutOfBoundsException) cause).isUpperBoundReached()) {
System.out.println("ops, upper bound reached.");
} else if (((CounterOutOfBoundsException) cause).isLowerBoundReached()) {
System.out.println("ops, lower bound reached.");
}
}
}
// now using the functional API
counter.addAndGet(-100).handle((v, throwable) -> {
if (throwable != null) {
Throwable cause = throwable.getCause();
if (cause instanceof CounterOutOfBoundsException) {
if (((CounterOutOfBoundsException) cause).isUpperBoundReached()) {
System.out.println("ops, upper bound reached.");
} else if (((CounterOutOfBoundsException) cause).isLowerBoundReached()) {
System.out.println("ops, lower bound reached.");
}
}
return null;
}
System.out.println("new value is " + v);
return null;
}).get();
| 1,208
| 35.636364
| 82
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigureTransportCustom.java
|
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().transport()
.defaultTransport()
.clusterName("prod-cluster")
//Uses a custom JGroups stack for cluster transport.
.addProperty("configurationFile", "my-jgroups-udp.xml")
.build();
| 288
| 40.285714
| 79
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/Author.java
|
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
public class Author {
@ProtoField(1)
final String name;
@ProtoField(2)
final String surname;
@ProtoFactory
Author(String name, String surname) {
this.name = name;
this.surname = surname;
}
// public Getter methods omitted for brevity
}
| 393
| 20.888889
| 59
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/SpringExternalizeSessions.java
|
@EnableInfinispanEmbeddedHttpSession
@Configuration
public class Config {
@Bean
public SpringEmbeddedCacheManagerFactoryBean springCacheManager() {
return new SpringEmbeddedCacheManagerFactoryBean();
}
//An optional configuration bean responsible for replacing the default
//cookie that obtains configuration.
//For more information refer to the Spring Session documentation.
@Bean
public HttpSessionIdResolver httpSessionIdResolver() {
return HeaderHttpSessionIdResolver.xAuthToken();
}
}
| 532
| 28.611111
| 73
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CustomJChannel.java
|
GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
JChannel jchannel = new JChannel();
// Configure the jchannel as needed.
JGroupsTransport transport = new JGroupsTransport(jchannel);
global.transport().transport(transport);
new DefaultCacheManager(global.build());
| 286
| 40
| 69
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ClusteredCounters.java
|
GlobalConfigurationBuilder globalConfigurationBuilder = ...;
CounterManagerConfigurationBuilder builder = globalConfigurationBuilder.addModule(CounterManagerConfigurationBuilder.class);
builder.numOwner(3).reliability(Reliability.CONSISTENT);
builder.addStrongCounter().name("c1").initialValue(1).storage(Storage.PERSISTENT);
builder.addStrongCounter().name("c2").initialValue(2).lowerBound(0).storage(Storage.VOLATILE);
builder.addStrongCounter().name("c3").initialValue(3).upperBound(5).storage(Storage.PERSISTENT);
builder.addStrongCounter().name("c4").initialValue(4).lowerBound(0).upperBound(10).storage(Storage.VOLATILE);
builder.addStrongCounter().name("c5").initialValue(0).upperBound(100).lifespan(60000);
builder.addWeakCounter().name("c6").initialValue(5).concurrencyLevel(1).storage(Storage.PERSISTENT);
| 816
| 80.7
| 124
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/EmbeddedCacheConfiguration.java
|
// Set up a clustered Cache Manager.
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
// Initialize the default Cache Manager.
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
// Create a distributed cache with synchronous replication.
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC);
// Obtain a volatile cache.
Cache<String, String> cache = cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE).getOrCreateCache("myCache", builder.build());
// Stop the Cache Manager.
cacheManager.stop();
| 669
| 54.833333
| 155
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/WriteOnlyMap.java
|
import org.infinispan.functional.EntryView.*;
import org.infinispan.functional.FunctionalMap.*;
WriteOnlyMap<String, String> writeOnlyMap = ...
ReadOnlyMap<String, String> readOnlyMap = ...
CompletableFuture<Void> writeFuture = writeOnlyMap.eval("key1", "value1",
(v, view) -> view.set(v));
CompletableFuture<String> readFuture = writeFuture.thenCompose(r ->
readOnlyMap.eval("key1", ReadEntryView::get));
readFuture.thenAccept(System.out::println);
| 458
| 37.25
| 73
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/RestClient.java
|
package org.infinispan;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
/**
* Rest example accessing a cache.
*
* @author Samuel Tauil (samuel@redhat.com)
*/
public class RestExample {
/**
* Method that puts a String value in cache.
*
* @param urlServerAddress URL containing the cache and the key to insert
* @param value Text to insert
* @param user Used for basic auth
* @param password Used for basic auth
*/
public void putMethod(String urlServerAddress, String value, String user, String password) throws IOException {
System.out.println("----------------------------------------");
System.out.println("Executing PUT");
System.out.println("----------------------------------------");
URL address = new URL(urlServerAddress);
System.out.println("executing request " + urlServerAddress);
HttpURLConnection connection = (HttpURLConnection) address.openConnection();
System.out.println("Executing put method of value: " + value);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "text/plain");
addAuthorization(connection, user, password);
connection.setDoOutput(true);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(connection.getOutputStream());
outputStreamWriter.write(value);
connection.connect();
outputStreamWriter.flush();
System.out.println("----------------------------------------");
System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
System.out.println("----------------------------------------");
connection.disconnect();
}
/**
* Method that gets a value by a key in url as param value.
*
* @param urlServerAddress URL containing the cache and the key to read
* @param user Used for basic auth
* @param password Used for basic auth
* @return String value
*/
public String getMethod(String urlServerAddress, String user, String password) throws IOException {
String line;
StringBuilder stringBuilder = new StringBuilder();
System.out.println("----------------------------------------");
System.out.println("Executing GET");
System.out.println("----------------------------------------");
URL address = new URL(urlServerAddress);
System.out.println("executing request " + urlServerAddress);
HttpURLConnection connection = (HttpURLConnection) address.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "text/plain");
addAuthorization(connection, user, password);
connection.setDoOutput(true);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
connection.connect();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append('\n');
}
System.out.println("Executing get method of value: " + stringBuilder.toString());
System.out.println("----------------------------------------");
System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
System.out.println("----------------------------------------");
connection.disconnect();
return stringBuilder.toString();
}
private void addAuthorization(HttpURLConnection connection, String user, String pass) {
String credentials = user + ":" + pass;
String basic = Base64.getEncoder().encodeToString(credentials.getBytes());
connection.setRequestProperty("Authorization", "Basic " + basic);
}
/**
* Main method example.
*/
public static void main(String[] args) throws IOException {
RestExample restExample = new RestExample();
String user = "user";
String pass = "pass";
restExample.putMethod("http://localhost:11222/rest/v2/caches/default/1", "Infinispan REST Test", user, pass);
restExample.getMethod("http://localhost:11222/rest/v2/caches/default/1", user, pass);
}
}
| 4,436
| 38.972973
| 117
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigRocksDbProperties.java
|
Properties props = new Properties();
props.put("database.max_background_compactions", "2");
props.put("data.write_buffer_size", "512MB");
Configuration cacheConfig = new ConfigurationBuilder().persistence()
.addStore(RocksDBStoreConfigurationBuilder.class)
.location("rocksdb/data")
.expiredLocation("rocksdb/expired")
.properties(props)
.build();
| 369
| 32.636364
| 68
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/LockingModePessimisticExplicitAcquire.java
|
tm.begin()
cache.getAdvancedCache().lock(K) // acquire cluster-wide lock on K
cache.put(K,V5) // guaranteed to succeed
tm.commit() // releases locks
| 190
| 37.2
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ReadWriteMapListener.java
|
import org.infinispan.functional.EntryView.*;
import org.infinispan.functional.FunctionalMap.*;
import org.infinispan.functional.Listeners.ReadWriteListeners.ReadWriteListener;
ReadWriteMap<String, String> rwMap = ...
AutoCloseable readWriteClose = rwMap.listeners.add(new ReadWriteListener<String, String>() {
@Override
public void onCreate(ReadEntryView<String, String> created) {
System.out.printf("Created: %s%n", created.get());
}
@Override
public void onModify(ReadEntryView<String, String> before, ReadEntryView<String, String> after) {
System.out.printf("Before: %s%n", before.get());
System.out.printf("After: %s%n", after.get());
}
@Override
public void onRemove(ReadEntryView<String, String> removed) {
System.out.printf("Removed: %s%n", removed.get());
}
);
AutoCloseable writeClose = rwMap.listeners.add(new WriteListener<String, String>() {
@Override
public void onWrite(ReadEntryView<K, V> written) {
System.out.printf("Written: %s%n", written.get());
}
);
// Either wrap handler in a try section to have it auto close...
try(readWriteClose) {
// Create/update/remove entries using read-write functional map API
...
}
// Or close manually
writeClose.close();
| 1,250
| 32.810811
| 100
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/NonBlocking.java
|
Set<CompletableFuture<?>> futures = new HashSet<>();
futures.add(cache.putAsync(key1, value1)); // does not block
futures.add(cache.putAsync(key2, value2)); // does not block
futures.add(cache.putAsync(key3, value3)); // does not block
// the remote calls for the 3 puts will effectively be executed
// in parallel, particularly useful if running in distributed mode
// and the 3 keys would typically be pushed to 3 different nodes
// in the cluster
// check that the puts completed successfully
for (CompletableFuture<?> f: futures) f.get();
| 545
| 41
| 66
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterEvent.java
|
public interface CounterEvent {
long getOldValue();
State getOldState();
long getNewValue();
State getNewState();
}
| 128
| 17.428571
| 31
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/StatisticsGlobalConfigurationBuilder.java
|
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder().cacheContainer().statistics(true);
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
Configuration builder = new ConfigurationBuilder();
builder.statistics().enable();
| 284
| 46.5
| 123
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/EmbeddedCacheManagerGetCache.java
|
EmbeddedCacheManager cm = new DefaultCacheManager("infinispan.xml");
Cache<Object, Object> replSyncCache = cm.getCache("replSyncCache");
Cache<Object, Object> replAsyncCache = cm.getCache("replAsyncCache");
Cache<Object, Object> invalidationSyncCache = cm.getCache("invalidationSyncCache");
| 291
| 57.4
| 83
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/PersistenceCliLoader.java
|
ConfigurationBuilder b = new ConfigurationBuilder();
b.persistence()
.addStore(CLInterfaceLoaderConfigurationBuilder.class)
.connectionString("jmx://192.0.2.0:4444/MyCacheManager/myCache");
| 198
| 38.8
| 69
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodCreateCacheWithXML.java
|
String cacheName = "CacheWithXMLConfiguration";
String xml = String.format("<distributed-cache name=\"%s\" mode=\"SYNC\">" +
"<encoding media-type=\"application/x-protostream\"/>" +
"<locking isolation=\"READ_COMMITTED\"/>" +
"<transaction mode=\"NON_XA\"/>" +
"<expiration lifespan=\"60000\" interval=\"20000\"/>" +
"</distributed-cache>" , cacheName);
remoteCacheManager.administration().getOrCreateCache(cacheName, new XMLStringConfiguration(xml));
| 599
| 65.666667
| 97
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/QuickstartDefaultCacheLifespan.java
|
//By default entries are immortal but we can override this on a per-key basis and provide lifespans.
cache.put("key", "value", 5, SECONDS);
assertTrue(cache.containsKey("key"));
Thread.sleep(10000);
| 199
| 39
| 100
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/HotRodOAuthBearer.java
|
String token = "..."; // Obtain the token from your OAuth2 provider
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("OAUTHBEARER")
.token(token);
| 358
| 34.9
| 67
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/InjectRemoteCacheQualifier.java
|
public class GreetingService {
@Inject
@Remote("greeting-cache")
private RemoteCache<String, String> cache;
...
}
| 132
| 13.777778
| 46
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/CounterListenerAdd.java
|
<T extends CounterListener> Handle<T> addListener(T listener);
| 63
| 31
| 62
|
java
|
null |
infinispan-main/documentation/src/main/asciidoc/topics/code_examples/ConfigEmbeddedCacheManagerDistribution.java
|
private static EmbeddedCacheManager createCacheManagerFromXml() throws IOException {
return new DefaultCacheManager("infinispan-distribution.xml");
}
| 153
| 37.5
| 84
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.