public static synchronized HotRodServer createServer() throws IOException {
    count++;
    if (server == null) {
      CACHEMANAGER = new DefaultCacheManager(CONFIG_FILE);

      CACHEMANAGER.start();
      // This doesn't work on IPv6, because the util assumes "127.0.0.1" ...
      // server = HotRodTestingUtil.startHotRodServer(cacheManager, HOST, PORT);

      server = new HotRodServer();
      String hostAddress = hostAddress();
      String hostPort = Integer.toString(hostPort());
      String timeoutStr = Integer.toString(TIMEOUT);
      Properties props = new Properties();
      props.setProperty(Main.PROP_KEY_HOST(), hostAddress);
      props.setProperty(Main.PROP_KEY_PORT(), hostPort);
      props.setProperty(Main.PROP_KEY_IDLE_TIMEOUT(), timeoutStr);
      props.setProperty(Main.PROP_KEY_PROXY_HOST(), hostAddress);
      props.setProperty(Main.PROP_KEY_PROXY_PORT(), hostPort);
      // System.out.println("Starting HotRot Server at " + hostAddress + ":" + hostPort);
      server.start(props, CACHEMANAGER);

      server.cacheManager().startCaches(CACHE_NAME);

      server
          .getCacheManager()
          .getCache(CACHE_NAME)
          .put("1", new String("value1")); // $NON-NLS-1$  //$NON-NLS-2$
      server
          .getCacheManager()
          .getCache(CACHE_NAME)
          .put("2", new String("value2")); // $NON-NLS-1$  //$NON-NLS-2$
    }
    return server;
  }
Example #2
0
 public static void main(String[] args) throws IOException {
   DefaultCacheManager cacheManager =
       new DefaultCacheManager("config-samples/lucene-demo-cache-config.xml");
   cacheManager.start();
   try {
     Cache<?, ?> cache = cacheManager.getCache();
     InfinispanDirectory directory = new InfinispanDirectory(cache);
     DemoDriver driver = new DemoDriver(directory, cache);
     driver.run();
   } finally {
     cacheManager.stop();
   }
 }
  @Override
  public synchronized void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties)
      throws ConfigurationException {
    String config = (String) properties.get(PROP_CONFIG);
    if (config == null) {
      throw new ConfigurationException(PROP_CONFIG, "Property must be set");
    }

    String instanceId = (String) properties.get(PROP_INSTANCE_ID);
    if (instanceId == null) {
      throw new ConfigurationException(PROP_INSTANCE_ID, "Property must be set");
    }

    try {
      URL configURL =
          new FileLookup()
              .lookupFileLocation(config, Thread.currentThread().getContextClassLoader());
      if (configURL == null) {
        throw new ConfigurationException(
            PROP_CONFIG, String.format("Failed to find the specified config '%s'.", config));
      }

      /* Unregister and destroy the old object. */
      deleted(pid);

      InputStream configStream = configURL.openStream();
      DefaultCacheManager cacheManager = new DefaultCacheManager(configStream);

      cacheManager.start();

      Hashtable<String, String> ht = new Hashtable<String, String>();
      ht.put(PROP_INSTANCE_ID, instanceId);
      ht.put(PROP_CONFIG, config);

      ServiceRegistration<EmbeddedCacheManager> serviceRegistration =
          bundleContext.registerService(EmbeddedCacheManager.class, cacheManager, ht);

      managedRegistrations.put(pid, serviceRegistration);
      cacheManagers.put(pid, cacheManager);
    } catch (Exception e) {
      throw new ConfigurationException(null, "Cannot start the CacheManager", e);
    }
  }
 @BeforeClass
 public static void startCacheManagers() {
   DEFAULT_CACHE_MANAGER.start();
   PRECONFIGURED_DEFAULT_CACHE_MANAGER.start();
 }