use of org.apache.geode.internal.logging.LoggingThreadGroup in project geode by apache.
the class WanLocatorDiscovererImpl method discover.
@Override
public void discover(int port, DistributionConfigImpl config, LocatorMembershipListener locatorListener, final String hostnameForClients) {
final LoggingThreadGroup loggingThreadGroup = LoggingThreadGroup.createThreadGroup("WAN Locator Discovery Logger Group", logger);
final ThreadFactory threadFactory = new ThreadFactory() {
public Thread newThread(final Runnable task) {
final Thread thread = new Thread(loggingThreadGroup, task, "WAN Locator Discovery Thread");
thread.setDaemon(true);
return thread;
}
};
this._executor = Executors.newCachedThreadPool(threadFactory);
exchangeLocalLocators(port, config, locatorListener, hostnameForClients);
exchangeRemoteLocators(port, config, locatorListener, hostnameForClients);
this._executor.shutdown();
}
use of org.apache.geode.internal.logging.LoggingThreadGroup in project geode by apache.
the class ClientCQImpl method executeWithInitialResults.
/**
* Start or resume executing the query. Gets or updates the CQ results and returns them.
*/
@Override
public <E> CqResults<E> executeWithInitialResults() throws CqClosedException, RegionNotFoundException, CqException {
synchronized (queuedEventsSynchObject) {
// until first call is completed.
while (queuedEvents != null) {
try {
queuedEventsSynchObject.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// At this point we know queuedEvents is null and no one is adding to queuedEvents yet.
this.queuedEvents = new ConcurrentLinkedQueue<CqEventImpl>();
}
if (CqQueryImpl.testHook != null) {
testHook.pauseUntilReady();
}
// Send CQ request to servers.
// If an exception is thrown, we need to clean up the queuedEvents
// or else client will hang on next executeWithInitialResults
CqResults initialResults;
try {
initialResults = (CqResults) executeCqOnRedundantsAndPrimary(true);
} catch (RegionNotFoundException | CqException | RuntimeException e) {
queuedEvents = null;
throw e;
}
// initial results can be added to the queue.
synchronized (queuedEventsSynchObject) {
// Invoke the CQ Listeners with the received CQ Events.
try {
if (!this.queuedEvents.isEmpty()) {
try {
Runnable r = new Runnable() {
@Override
public void run() {
Object[] eventArray = null;
if (CqQueryImpl.testHook != null) {
testHook.setEventCount(queuedEvents.size());
}
// Synchronization for the executer thread.
synchronized (queuedEventsSynchObject) {
try {
eventArray = queuedEvents.toArray();
// Process through the events
for (Object cqEvent : eventArray) {
cqService.invokeListeners(cqName, ClientCQImpl.this, (CqEventImpl) cqEvent);
stats.decQueuedCqListenerEvents();
}
} finally {
// Make sure that we notify waiting threads or else possible dead lock
queuedEvents.clear();
queuedEvents = null;
queuedEventsSynchObject.notify();
}
}
}
};
final LoggingThreadGroup group = LoggingThreadGroup.createThreadGroup("CQEventHandler", logger);
Thread thread = new Thread(group, r, "CQEventHandler For " + cqName);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Exception while invoking the CQ Listener with queued events.", ex);
}
}
} else {
queuedEvents = null;
}
} finally {
queuedEventsSynchObject.notify();
}
return initialResults;
}
}
use of org.apache.geode.internal.logging.LoggingThreadGroup in project geode by apache.
the class GemFireCacheImpl method getQueryMonitor.
/**
* Returns the QueryMonitor instance based on system property MAX_QUERY_EXECUTION_TIME.
*
* @since GemFire 6.0
*/
@Override
public QueryMonitor getQueryMonitor() {
// Check to see if monitor is required if ResourceManager critical heap percentage is set
// or whether we override it with the system variable;
boolean monitorRequired = !this.queryMonitorDisabledForLowMem && queryMonitorRequiredForResourceManager;
// Added for DUnit test purpose, which turns-on and off the this.testMaxQueryExecutionTime.
if (!(MAX_QUERY_EXECUTION_TIME > 0 || this.testMaxQueryExecutionTime > 0 || monitorRequired)) {
// Else send null, so that the QueryMonitor is turned-off.
return null;
}
// Return the QueryMonitor service if MAX_QUERY_EXECUTION_TIME is set or it is required by the
// ResourceManager and not overridden by system property.
boolean needQueryMonitor = MAX_QUERY_EXECUTION_TIME > 0 || this.testMaxQueryExecutionTime > 0 || monitorRequired;
if (needQueryMonitor && this.queryMonitor == null) {
synchronized (this.queryMonitorLock) {
if (this.queryMonitor == null) {
int maxTime = MAX_QUERY_EXECUTION_TIME > this.testMaxQueryExecutionTime ? MAX_QUERY_EXECUTION_TIME : this.testMaxQueryExecutionTime;
if (monitorRequired && maxTime < 0) {
// this means that the resource manager is being used and we need to monitor query
// memory usage
// If no max execution time has been set, then we will default to five hours
maxTime = FIVE_HOURS;
}
this.queryMonitor = new QueryMonitor(maxTime);
final LoggingThreadGroup group = LoggingThreadGroup.createThreadGroup("QueryMonitor Thread Group", logger);
Thread qmThread = new Thread(group, this.queryMonitor, "QueryMonitor Thread");
qmThread.setDaemon(true);
qmThread.start();
if (logger.isDebugEnabled()) {
logger.debug("QueryMonitor thread started.");
}
}
}
}
return this.queryMonitor;
}
use of org.apache.geode.internal.logging.LoggingThreadGroup in project geode by apache.
the class ConcurrentParallelGatewaySenderEventProcessor method stopProcessing.
@Override
public void stopProcessing() {
if (!this.isAlive()) {
return;
}
setIsStopped(true);
final LoggingThreadGroup loggingThreadGroup = LoggingThreadGroup.createThreadGroup("ConcurrentParallelGatewaySenderEventProcessor Logger Group", logger);
ThreadFactory threadFactory = new ThreadFactory() {
public Thread newThread(final Runnable task) {
final Thread thread = new Thread(loggingThreadGroup, task, "ConcurrentParallelGatewaySenderEventProcessor Stopper Thread");
thread.setDaemon(true);
return thread;
}
};
List<SenderStopperCallable> stopperCallables = new ArrayList<SenderStopperCallable>();
for (ParallelGatewaySenderEventProcessor parallelProcessor : this.processors) {
stopperCallables.add(new SenderStopperCallable(parallelProcessor));
}
ExecutorService stopperService = Executors.newFixedThreadPool(processors.length, threadFactory);
try {
List<Future<Boolean>> futures = stopperService.invokeAll(stopperCallables);
for (Future<Boolean> f : futures) {
try {
Boolean b = f.get();
if (logger.isDebugEnabled()) {
logger.debug("ConcurrentParallelGatewaySenderEventProcessor: {} stopped dispatching: {}", (b ? "Successfully" : "Unsuccesfully"), this);
}
} catch (ExecutionException e) {
// we don't expect any exception but if caught then eat it and log warning
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySender_0_CAUGHT_EXCEPTION_WHILE_STOPPING_1, sender), e.getCause());
}
}
} catch (InterruptedException e) {
throw new InternalGemFireException(e);
} catch (RejectedExecutionException rejectedExecutionEx) {
throw rejectedExecutionEx;
}
stopperService.shutdown();
closeProcessor();
if (logger.isDebugEnabled()) {
logger.debug("ConcurrentParallelGatewaySenderEventProcessor: Stopped dispatching: {}", this);
}
}
use of org.apache.geode.internal.logging.LoggingThreadGroup in project geode by apache.
the class ConcurrentSerialGatewaySenderEventProcessor method stopProcessing.
@Override
public void stopProcessing() {
if (!this.isAlive()) {
return;
}
setIsStopped(true);
final LoggingThreadGroup loggingThreadGroup = LoggingThreadGroup.createThreadGroup("ConcurrentSerialGatewaySenderEventProcessor Logger Group", logger);
ThreadFactory threadFactory = new ThreadFactory() {
public Thread newThread(final Runnable task) {
final Thread thread = new Thread(loggingThreadGroup, task, "ConcurrentSerialGatewaySenderEventProcessor Stopper Thread");
thread.setDaemon(true);
return thread;
}
};
List<SenderStopperCallable> stopperCallables = new ArrayList<SenderStopperCallable>();
for (SerialGatewaySenderEventProcessor serialProcessor : this.processors) {
stopperCallables.add(new SenderStopperCallable(serialProcessor));
}
ExecutorService stopperService = Executors.newFixedThreadPool(processors.size(), threadFactory);
try {
List<Future<Boolean>> futures = stopperService.invokeAll(stopperCallables);
for (Future<Boolean> f : futures) {
try {
boolean b = f.get();
if (logger.isDebugEnabled()) {
logger.debug("ConcurrentSerialGatewaySenderEventProcessor: {} stopped dispatching: {}", (b ? "Successfully" : "Unsuccesfully"), this);
}
} catch (ExecutionException e) {
// we don't expect any exception but if caught then eat it and log
// warning
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySender_0_CAUGHT_EXCEPTION_WHILE_STOPPING_1, new Object[] { sender, e.getCause() }));
}
}
} catch (InterruptedException e) {
throw new InternalGemFireException(e.getMessage());
} catch (RejectedExecutionException rejectedExecutionEx) {
throw rejectedExecutionEx;
}
// shutdown the stopperService. This will release all the stopper threads
stopperService.shutdown();
closeProcessor();
if (logger.isDebugEnabled()) {
logger.debug("ConcurrentSerialGatewaySenderEventProcessor: Stopped dispatching: {}", this);
}
}
Aggregations