@Before
 public void setUp() throws Exception {
   Properties p = new Properties();
   p.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
   p.setProperty(DistributionConfig.OFF_HEAP_MEMORY_SIZE_NAME, "1m");
   this.ds = DistributedSystem.connect(p);
   this.cache = (GemFireCacheImpl) CacheFactory.create(this.ds);
   logger.info(addExpectedAbove);
   logger.info(addExpectedBelow);
 }
Пример #2
0
 private static CommandManager startGemFire() {
   Properties pr = new Properties();
   pr.put("jmx-manager", "true");
   pr.put("jmx-manager-start", "true");
   DistributedSystem ds = DistributedSystem.connect(pr);
   Cache cache = new CacheFactory().create();
   GemFireCacheImpl impl = (GemFireCacheImpl) cache;
   ManagementService service = ManagementService.getManagementService(cache);
   CommandManager manager = CommandManager.getExisting();
   return manager;
 }
Пример #3
0
 /**
  * Creates a new cache that uses the configured distributed system. If a connected distributed
  * system already exists it will be used if it is compatible with the properties on this factory.
  * Otherwise a a distributed system will be created with the configured properties. If a cache
  * already exists it will be returned.
  *
  * <p>If the cache does need to be created it will also be initialized from cache.xml if it
  * exists.
  *
  * @return the created or already existing singleton cache
  * @throws CacheXmlException If a problem occurs while parsing the declarative caching XML file.
  * @throws TimeoutException If a {@link Region#put(Object, Object)} times out while initializing
  *     the cache.
  * @throws CacheWriterException If a <code>CacheWriterException</code> is thrown while
  *     initializing the cache.
  * @throws GatewayException If a <code>GatewayException</code> is thrown while initializing the
  *     cache.
  * @throws RegionExistsException If the declarative caching XML file describes a region that
  *     already exists (including the root region).
  * @throws ManagementException If the jmx manager can not be initialized.
  * @since 6.5
  */
 public Cache create()
     throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
   synchronized (CacheFactory.class) {
     DistributedSystem ds = null;
     if (this.dsProps.isEmpty()) {
       // any ds will do
       ds = InternalDistributedSystem.getConnectedInstance();
     }
     if (ds == null) {
       ds = DistributedSystem.connect(this.dsProps);
     }
     return create(ds, true, cacheConfig);
   }
 }
  /** Creates and starts the server instance */
  private int createServer() {
    CacheServer server = null;
    try {
      Properties p = new Properties();
      // make it a loner
      p.put("mcast-port", "0");
      p.put("locators", "");

      this.system = DistributedSystem.connect(p);
      this.cache = CacheFactory.create(system);
      server = this.cache.addCacheServer();
      int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
      server.setMaximumTimeBetweenPings(TIME_BETWEEN_PINGS);
      server.setMaxThreads(getMaxThreads());
      server.setPort(port);
      server.start();
    } catch (Exception e) {
      e.printStackTrace();
      fail("Failed to create server");
    }
    return server.getPort();
  }
  public static void main(String[] args) throws Exception {

    Properties props = new Properties();
    props.setProperty("name", "CqServer");
    props.setProperty("log-level", "warning");

    System.out.println("\nConnecting to the distributed system and creating the cache.");
    DistributedSystem ds = DistributedSystem.connect(props);
    Cache cache = CacheFactory.create(ds);

    // Create region.
    AttributesFactory factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setScope(Scope.DISTRIBUTED_ACK);
    Region testRegion = cache.createRegion("test-cq", factory.create());
    System.out.println("Test region, " + testRegion.getFullPath() + ", created in cache.");

    // Start Cache Server.
    CacheServer server = cache.addCacheServer();
    server.setPort(40404);
    server.setNotifyBySubscription(true);
    server.start();

    System.out.println("Waiting for signal");
    // wait for signal
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    bufferedReader.readLine();

    System.out.println("Received signal");

    testRegion.put("one", 1);
    testRegion.put("two", 2);
    testRegion.put("three", 3);

    System.out.println("Waiting for shutdown");
    bufferedReader.readLine();
  }