use of org.apache.geode.internal.cache.CacheServerImpl 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.internal.cache.CacheServerImpl in project geode by apache.
the class CacheServerBridge method getClientVersion.
public Version getClientVersion(ClientConnInfo connInfo) {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
if (cache.getCacheServers().size() == 0) {
return null;
}
CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
if (server == null) {
return null;
}
AcceptorImpl acceptorImpl = server.getAcceptor();
if (acceptorImpl == null) {
return null;
}
ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
boolean flag = false;
if (connInfo.toString().contains("primary=true")) {
flag = true;
}
for (ServerConnection conn : serverConnections) {
ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
ClientConnInfo cci = new ClientConnInfo(conn.getProxyID(), conn.getSocketHost(), conn.getSocketPort(), flag);
if (connInfo.toString().equals(cci.toString())) {
return cliIdFrmProxy.getClientVersion();
}
}
// check form ccp
ClientProxyMembershipID proxyId = connInfo.getClientId();
CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
if (proxy != null) {
return proxy.getVersion();
} else {
return null;
}
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class GatewayReceiverMBeanBridge method getConnectedGatewaySenders.
public String[] getConnectedGatewaySenders() {
Set<String> uniqueIds = null;
AcceptorImpl acceptor = ((CacheServerImpl) rcv.getServer()).getAcceptor();
Set<ServerConnection> serverConnections = acceptor.getAllServerConnections();
if (serverConnections != null && serverConnections.size() > 0) {
uniqueIds = new HashSet<String>();
for (ServerConnection conn : serverConnections) {
uniqueIds.add(conn.getMembershipID());
}
String[] allConnectedClientStr = new String[uniqueIds.size()];
return uniqueIds.toArray(allConnectedClientStr);
}
return new String[0];
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class ContunuousQueryFunction method execute.
@Override
public void execute(FunctionContext context) {
try {
String clientID = (String) context.getArguments();
InternalCache cache = getCache();
if (cache.getCacheServers().size() > 0) {
CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
if (server != null) {
AcceptorImpl acceptorImpl = server.getAcceptor();
if (acceptorImpl != null) {
CacheClientNotifier cacheClientNotifier = acceptorImpl.getCacheClientNotifier();
if (cacheClientNotifier != null) {
Collection<CacheClientProxy> cacheClientProxySet = cacheClientNotifier.getClientProxies();
ClientInfo clientInfo = null;
boolean foundClientinCCP = false;
Iterator<CacheClientProxy> it = cacheClientProxySet.iterator();
while (it.hasNext()) {
CacheClientProxy ccp = it.next();
if (ccp != null) {
String clientIdFromProxy = ccp.getProxyID().getDSMembership();
if (clientIdFromProxy != null && clientIdFromProxy.equals(clientID)) {
foundClientinCCP = true;
String durableId = ccp.getProxyID().getDurableId();
boolean isPrimary = ccp.isPrimary();
clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), (isPrimary == true ? cache.getDistributedSystem().getDistributedMember().getId() : ""), (isPrimary == false ? cache.getDistributedSystem().getDistributedMember().getId() : ""));
break;
}
}
}
// try getting from server connections
if (foundClientinCCP == false) {
ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
for (ServerConnection conn : serverConnections) {
ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
if (clientID.equals(cliIdFrmProxy.getDSMembership())) {
String durableId = cliIdFrmProxy.getDurableId();
clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), "N.A.", "N.A.");
}
}
}
context.getResultSender().lastResult(clientInfo);
}
}
}
}
} catch (Exception e) {
context.getResultSender().lastResult("Exception in ContunuousQueryFunction =" + e.getMessage());
}
context.getResultSender().lastResult(null);
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.
@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
final String regionName1 = this.getName() + "-1";
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setConcurrencyChecksEnabled(false);
createRegion(regionName1, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
// Create server1.
server1.invoke(createServer);
final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
Region region1 = null;
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
regionFactory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
region1 = createRegion(regionName1, regionFactory.create());
region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
}
};
// Create client.
client.invoke(createPool);
// Init values at server.
server1.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 20; i++) {
region1.put("key-string-" + i, "value-" + i);
}
}
});
// Put some values on the client.
client.invoke(new CacheSerializableRunnable("Put values client") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 10; i++) {
region1.put("key-string-" + i, "client-value-" + i);
}
}
});
SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
String pName = region1.getAttributes().getPoolName();
region1.localDestroyRegion();
PoolImpl p = (PoolImpl) PoolManager.find(pName);
p.destroy();
}
};
client.invoke(closePool);
SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {
public void run2() throws CacheException {
for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
CacheServerImpl bsi = (CacheServerImpl) bi.next();
final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 62 * 1000, 200, true);
assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
}
}
};
server1.invoke(validateClientRegisterUnRegister);
server1.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
Aggregations