|
// infinispan |
|
import org.infinispan.Cache; |
|
import org.infinispan.configuration.global.*; |
|
import org.infinispan.configuration.cache.*; |
|
import org.infinispan.manager.*; |
|
|
|
// os signals |
|
import sun.misc.Signal; |
|
import sun.misc.SignalHandler; |
|
import java.lang.reflect.*; |
|
|
|
@SuppressWarnings("deprecation") |
|
public class InfinispanHelloWorld |
|
{ |
|
public static void main (String[] args) |
|
{ |
|
DebugSignalHandler.listenTo("HUP"); |
|
|
|
System.out.println("Hello World!"); |
|
try { |
|
DefaultCacheManager m = new DefaultCacheManager(System.getProperty("user.dir") + "/config.xml"); |
|
Cache<String, String> cache = m.getCache(); |
|
System.out.println("---"); |
|
|
|
System.out.println("get hello1 " + cache.get("hello1")); |
|
System.out.println("get hello2 " + cache.get("hello2")); |
|
System.out.println("get hello3 " + cache.get("hello3")); |
|
System.out.println("get hello4 " + cache.get("hello4")); |
|
|
|
System.out.println("put hello1 " + cache.put("hello1", "world")); |
|
System.out.println("put hello2 " + cache.put("hello2", "world")); |
|
System.out.println("put hello3 " + cache.put("hello3", "world")); |
|
System.out.println("put hello4 " + cache.put("hello4", "world")); |
|
|
|
System.out.println("rm hello4 " + cache.remove("hello4")); |
|
|
|
System.out.println("get hello1 " + cache.get("hello1")); |
|
System.out.println("get hello2 " + cache.get("hello2")); |
|
System.out.println("get hello3 " + cache.get("hello3")); |
|
System.out.println("get hello4 " + cache.get("hello4")); |
|
} catch (Exception e) { |
|
System.out.println("error " + e.getMessage()); |
|
} |
|
} |
|
|
|
} |
|
|
|
@SuppressWarnings("deprecation") |
|
class DebugSignalHandler implements SignalHandler |
|
{ |
|
public static void listenTo(String name) { |
|
Signal signal = new Signal(name); |
|
Signal.handle(signal, new DebugSignalHandler()); |
|
} |
|
|
|
public void handle(Signal signal) { |
|
System.out.println("Signal: " + signal.toString().trim()); |
|
try { |
|
DefaultCacheManager m = new DefaultCacheManager(System.getProperty("user.dir") + "/config.xml"); |
|
Cache<String, String> cache = m.getCache(); |
|
System.out.println("---"); |
|
System.out.println("rm hello3 " + cache.remove("hello3")); |
|
System.out.println("get hello1 " + cache.get("hello1")); |
|
System.out.println("get hello2 " + cache.get("hello2")); |
|
System.out.println("get hello3 " + cache.get("hello3")); |
|
System.out.println("get hello4 " + cache.get("hello4")); |
|
} catch (Exception e) { |
|
System.out.println("error " + e.getMessage()); |
|
} |
|
} |
|
} |
|
|
|
|