use of org.apache.geode.cache.server.CacheServer in project geode by apache.
the class InternalDistributedSystem method createAndStartCacheServers.
/**
* after an auto-reconnect we may need to recreate a cache server and start it
*/
public void createAndStartCacheServers(List<CacheServerCreation> cacheServerCreation, InternalCache cache) {
List<CacheServer> servers = cache.getCacheServers();
// to recreate it.
if (servers.isEmpty() && cacheServerCreation != null) {
for (CacheServerCreation bridge : cacheServerCreation) {
CacheServerImpl impl = (CacheServerImpl) cache.addCacheServer();
impl.configureFrom(bridge);
}
}
servers = cache.getCacheServers();
for (CacheServer server : servers) {
try {
if (!server.isRunning()) {
server.start();
}
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.CacheCreation_WHILE_STARTING_CACHE_SERVER_0.toLocalizedString(server), ex);
}
}
}
use of org.apache.geode.cache.server.CacheServer in project geode by apache.
the class RestAPIsWithSSLDUnitTest method startBridgeServer.
@SuppressWarnings("deprecation")
protected int startBridgeServer(String hostName, int restServicePort, final String locators, final String[] regions, final Properties sslProperties, boolean clusterLevel) {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(restServicePort));
System.setProperty("javax.net.debug", "ssl,handshake");
props = configureSSL(props, sslProperties, clusterLevel);
DistributedSystem ds = getSystem(props);
InternalCache cache = (InternalCache) CacheFactory.create(ds);
cache.setReadSerialized(true);
AttributesFactory factory = new AttributesFactory();
factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
CacheServer server = cache.addCacheServer();
server.setPort(0);
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
remoteObjects.put(CACHE_KEY, cache);
return server.getPort();
}
use of org.apache.geode.cache.server.CacheServer in project geode by apache.
the class ConnectionPoolDUnitTest method startBridgeServer.
protected void startBridgeServer(int port, int socketBufferSize, long loadPollInterval) throws IOException {
Cache cache = getCache();
CacheServer bridge = cache.addCacheServer();
bridge.setPort(port);
if (socketBufferSize != -1) {
bridge.setSocketBufferSize(socketBufferSize);
}
bridge.setMaxThreads(getMaxThreads());
bridge.setLoadPollInterval(loadPollInterval);
bridge.start();
bridgeServerPort = bridge.getPort();
}
use of org.apache.geode.cache.server.CacheServer in project geode by apache.
the class ConnectionPoolImplJUnitTest method testCreatePool.
@Test
public void testCreatePool() throws Exception {
CacheServer server1 = cache.addCacheServer();
int port1 = port;
server1.setPort(port1);
server1.start();
PoolFactory cpf = PoolManager.createFactory();
cpf.addServer("localhost", port1);
cpf.setSubscriptionEnabled(true);
cpf.setSubscriptionRedundancy(0);
PoolImpl pool = (PoolImpl) cpf.create("pool1");
ServerLocation location1 = new ServerLocation("localhost", port1);
Op testOp = new Op() {
public Object attempt(Connection cnx) throws Exception {
return cnx.getServer();
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
};
assertEquals(location1, pool.executeOnPrimary(testOp));
assertEquals(location1, pool.executeOnQueuesAndReturnPrimaryResult(testOp));
}
use of org.apache.geode.cache.server.CacheServer in project geode by apache.
the class ConnectionPoolImplJUnitTest method testExecuteOp.
@Test
public void testExecuteOp() throws Exception {
CacheServer server1 = cache.addCacheServer();
CacheServer server2 = cache.addCacheServer();
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
int port1 = ports[0];
int port2 = ports[1];
server1.setPort(port1);
server2.setPort(port2);
server1.start();
server2.start();
PoolFactory cpf = PoolManager.createFactory();
cpf.addServer("localhost", port2);
cpf.addServer("localhost", port1);
PoolImpl pool = (PoolImpl) cpf.create("pool1");
ServerLocation location1 = new ServerLocation("localhost", port1);
ServerLocation location2 = new ServerLocation("localhost", port2);
Op testOp = new Op() {
int attempts = 0;
public Object attempt(Connection cnx) throws Exception {
if (attempts == 0) {
attempts++;
throw new SocketTimeoutException();
} else {
return cnx.getServer();
}
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
};
// TODO - set retry attempts, and throw in some assertions
// about how many times we retry
ServerLocation usedServer = (ServerLocation) pool.execute(testOp);
assertTrue("expected " + location1 + " or " + location2 + ", got " + usedServer, location1.equals(usedServer) || location2.equals(usedServer));
testOp = new Op() {
public Object attempt(Connection cnx) throws Exception {
throw new SocketTimeoutException();
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
};
try {
usedServer = (ServerLocation) pool.execute(testOp);
fail("Should have failed");
} catch (ServerConnectivityException expected) {
// do nothing
}
}
Aggregations