use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class ClientStatsManager method publishClientStats.
/**
* This method publishes the client stats using the admin region.
*
* @param pool Connection pool which may be used for admin region.
*/
public static synchronized void publishClientStats(PoolImpl pool) {
InternalCache currentCache = GemFireCacheImpl.getInstance();
if (!initializeStatistics(currentCache)) {
// handles null case too
return;
}
LogWriterI18n logger = currentCache.getLoggerI18n();
if (logger.fineEnabled())
logger.fine("Entering ClientStatsManager#publishClientStats...");
ClientHealthStats stats = getClientHealthStats(currentCache, pool);
try {
InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
ServerRegionProxy regionProxy = new ServerRegionProxy(ClientHealthMonitoringRegion.ADMIN_REGION_NAME, pool);
EventID eventId = new EventID(ds);
@Released EntryEventImpl event = new EntryEventImpl((Object) null);
try {
event.setEventId(eventId);
regionProxy.putForMetaRegion(ds.getMemberId(), stats, null, event, null, true);
} finally {
event.release();
}
} catch (DistributedSystemDisconnectedException e) {
throw e;
} catch (CacheWriterException cwx) {
pool.getCancelCriterion().checkCancelInProgress(cwx);
currentCache.getCancelCriterion().checkCancelInProgress(cwx);
// TODO: Need to analyze these exception scenarios.
logger.warning(LocalizedStrings.ClientStatsManager_FAILED_TO_SEND_CLIENT_HEALTH_STATS_TO_CACHESERVER, cwx);
} catch (Exception e) {
pool.getCancelCriterion().checkCancelInProgress(e);
currentCache.getCancelCriterion().checkCancelInProgress(e);
logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e);
}
if (logger.fineEnabled()) {
logger.fine("Exiting ClientStatsManager#publishClientStats.");
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class InternalInstantiator method sendRegistrationMessage.
/**
* If we are connected to a distributed system, send a message to other members telling them about
* a newly-registered instantiator.
*/
private static void sendRegistrationMessage(Instantiator s) {
InternalDistributedSystem system = InternalDistributedSystem.getAnyInstance();
if (system != null) {
RegistrationMessage m = null;
if (s.getContext() == null) {
m = new RegistrationMessage(s);
} else {
m = new RegistrationContextMessage(s);
}
system.getDistributionManager().putOutgoing(m);
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class MemberMBeanBridge method fetchLog.
/**
* @return log of the member.
*/
public String fetchLog(int numLines) {
if (numLines > ManagementConstants.MAX_SHOW_LOG_LINES) {
numLines = ManagementConstants.MAX_SHOW_LOG_LINES;
}
if (numLines == 0 || numLines < 0) {
numLines = ManagementConstants.DEFAULT_SHOW_LOG_LINES;
}
String childTail = null;
String mainTail = null;
try {
InternalDistributedSystem sys = system;
LogWriterAppender lwa = LogWriterAppenders.getAppender(LogWriterAppenders.Identifier.MAIN);
if (lwa != null) {
childTail = BeanUtilFuncs.tailSystemLog(lwa.getChildLogFile(), numLines);
mainTail = BeanUtilFuncs.tailSystemLog(sys.getConfig(), numLines);
if (mainTail == null) {
mainTail = LocalizedStrings.TailLogResponse_NO_LOG_FILE_WAS_SPECIFIED_IN_THE_CONFIGURATION_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
}
} else {
Assert.assertTrue(false, "TailLogRequest/Response processed in application vm with shared logging.");
}
} catch (IOException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.TailLogResponse_ERROR_OCCURRED_WHILE_READING_SYSTEM_LOG__0, e));
mainTail = "";
}
if (childTail == null && mainTail == null) {
return LocalizedStrings.SystemMemberImpl_NO_LOG_FILE_CONFIGURED_LOG_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
} else {
StringBuilder result = new StringBuilder();
if (mainTail != null) {
result.append(mainTail);
}
if (childTail != null) {
result.append(getLineSeparator()).append(LocalizedStrings.SystemMemberImpl_TAIL_OF_CHILD_LOG.toLocalizedString()).append(getLineSeparator());
result.append(childTail);
}
return result.toString();
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class GeodeRedisServer method startRedisServer.
/**
* Helper method to start the server listening for connections. The server is bound to the port
* specified by {@link GeodeRedisServer#serverPort}
*
* @throws IOException
* @throws InterruptedException
*/
private void startRedisServer() throws IOException, InterruptedException {
ThreadFactory selectorThreadFactory = new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("GeodeRedisServer-SelectorThread-" + counter.incrementAndGet());
t.setDaemon(true);
return t;
}
};
ThreadFactory workerThreadFactory = new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("GeodeRedisServer-WorkerThread-" + counter.incrementAndGet());
return t;
}
};
bossGroup = null;
workerGroup = null;
Class<? extends ServerChannel> socketClass = null;
if (singleThreadPerConnection) {
bossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, selectorThreadFactory);
workerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, workerThreadFactory);
socketClass = OioServerSocketChannel.class;
} else {
bossGroup = new NioEventLoopGroup(this.numSelectorThreads, selectorThreadFactory);
workerGroup = new NioEventLoopGroup(this.numWorkerThreads, workerThreadFactory);
socketClass = NioServerSocketChannel.class;
}
InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
String pwd = system.getConfig().getRedisPassword();
final byte[] pwdB = Coder.stringToBytes(pwd);
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(socketClass).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
if (logger.fineEnabled())
logger.fine("GeodeRedisServer-Connection established with " + ch.remoteAddress());
ChannelPipeline p = ch.pipeline();
p.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
p.addLast(ExecutionHandlerContext.class.getSimpleName(), new ExecutionHandlerContext(ch, cache, regionCache, GeodeRedisServer.this, pwdB));
}
}).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_RCVBUF, getBufferSize()).childOption(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, GeodeRedisServer.connectTimeoutMillis).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
// Bind and start to accept incoming connections.
ChannelFuture f = b.bind(new InetSocketAddress(getBindAddress(), serverPort)).sync();
if (this.logger.infoEnabled()) {
String logMessage = "GeodeRedisServer started {" + getBindAddress() + ":" + serverPort + "}, Selector threads: " + this.numSelectorThreads;
if (this.singleThreadPerConnection)
logMessage += ", One worker thread per connection";
else
logMessage += ", Worker threads: " + this.numWorkerThreads;
this.logger.info(logMessage);
}
this.serverChannel = f.channel();
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class ClientRegionFactoryJUnitTest method tearDown.
@After
public void tearDown() throws Exception {
InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
if (ids != null && ids.isConnected()) {
if (r1 != null) {
this.cleanUpRegion(r1);
}
if (r2 != null) {
this.cleanUpRegion(r2);
}
if (r3 != null) {
this.cleanUpRegion(r3);
}
if (sr1 != null) {
this.cleanUpRegion(sr1);
}
ids.disconnect();
}
this.distSys = null;
this.cache = null;
}
Aggregations