List of usage examples for org.apache.shiro.util ThreadState clear
void clear();
From source file:com.gemstone.gemfire.internal.cache.tier.sockets.CacheClientProxy.java
License:Apache License
/** * Delivers the message to the client representing this client proxy. * @param conflatable /*from w w w . j a v a 2 s. c o m*/ */ protected void deliverMessage(Conflatable conflatable) { ThreadState state = GeodeSecurityUtil.bindSubject(this.subject); ClientUpdateMessage clientMessage = null; if (conflatable instanceof HAEventWrapper) { clientMessage = ((HAEventWrapper) conflatable).getClientUpdateMessage(); } else { clientMessage = (ClientUpdateMessage) conflatable; } this._statistics.incMessagesReceived(); // post process if (GeodeSecurityUtil.needPostProcess()) { Object oldValue = clientMessage.getValue(); if (clientMessage.valueIsObject()) { Object newValue = GeodeSecurityUtil.postProcess(clientMessage.getRegionName(), clientMessage.getKeyOfInterest(), EntryEventImpl.deserialize((byte[]) oldValue)); try { clientMessage.setLatestValue(BlobHelper.serializeToBlob(newValue)); } catch (IOException e) { throw new GemFireIOException("Exception serializing entry value", e); } } else { Object newValue = GeodeSecurityUtil.postProcess(clientMessage.getRegionName(), clientMessage.getKeyOfInterest(), oldValue); clientMessage.setLatestValue(newValue); } } if (clientMessage.needsNoAuthorizationCheck() || postDeliverAuthCheckPassed(clientMessage)) { // If dispatcher is getting initialized, add the event to temporary queue. if (this.messageDispatcherInit) { synchronized (this.queuedEventsSync) { if (this.messageDispatcherInit) { // Check to see value did not changed while getting the synchronize lock. if (logger.isDebugEnabled()) { logger.debug( "Message dispatcher for proxy {} is getting initialized. Adding message to the queuedEvents.", this); } this.queuedEvents.add(conflatable); return; } } } if (this._messageDispatcher != null) { this._messageDispatcher.enqueueMessage(conflatable); } else { this._statistics.incMessagesFailedQueued(); if (logger.isDebugEnabled()) { logger.debug( "Message is not added to the queue. Message dispatcher for proxy: {} doesn't exist.", this); } } } else { this._statistics.incMessagesFailedQueued(); } if (state != null) state.clear(); }
From source file:com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.java
License:Apache License
private void doNormalMsg() { Message msg = null;/*from www .ja v a 2 s . c o m*/ msg = BaseCommand.readRequest(this); ThreadState threadState = null; try { if (msg != null) { //this.logger.fine("donormalMsg() msgType " + msg.getMessageType()); // Since this thread is not interrupted when the cache server is // shutdown, // test again after a message has been read. This is a bit of a hack. I // think this thread should be interrupted, but currently AcceptorImpl // doesn't keep track of the threads that it launches. if (!this.processMessages || (crHelper.isShutdown())) { if (logger.isDebugEnabled()) { logger.debug("{} ignoring message of type {} from client {} due to shutdown.", getName(), MessageType.getString(msg.getMessageType()), this.proxyId); } return; } if (msg.getMessageType() != MessageType.PING) { // check for invalid number of message parts if (msg.getNumberOfParts() <= 0) { failureCount++; if (failureCount > 3) { this.processMessages = false; return; } else { return; } } } if (logger.isTraceEnabled()) { logger.trace("{} received {} with txid {}", getName(), MessageType.getString(msg.getMessageType()), msg.getTransactionId()); if (msg.getTransactionId() < -1) { // TODO:WTF: why is this happening? msg.setTransactionId(-1); } } if (msg.getMessageType() != MessageType.PING) { // we have a real message (non-ping), // so let's call receivedPing to let the CHM know client is busy acceptor.getClientHealthMonitor().receivedPing(this.proxyId); } Command command = getCommand(Integer.valueOf(msg.getMessageType())); if (command == null) { command = Default.getCommand(); } // if a subject exists for this uniqueId, binds the subject to this thread so that we can do authorization later if (AcceptorImpl.isIntegratedSecurity() && !isInternalMessage()) { long uniqueId = getUniqueId(); Subject subject = this.clientUserAuths.getSubject(uniqueId); if (subject != null) { threadState = GeodeSecurityUtil.bindSubject(subject); } } command.execute(msg, this); } } finally { // Keep track of the fact that a message is no longer being // processed. setNotProcessingMessage(); clearRequestMsg(); if (threadState != null) { threadState.clear(); } } }
From source file:com.sonicle.webtop.core.app.servlet.DocEditor.java
License:Open Source License
@Override protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebTopApp wta = WebTopApp.get(request); ThreadState threadState = new SubjectThreadState(wta.getAdminSubject()); threadState.bind();/*from w w w . j a va 2 s . c o m*/ try { processRequestAsAdmin(request, response); } catch (Throwable t) { logger.error("Error fulfilling request", t); throw t; } finally { threadState.clear(); } }
From source file:com.sonicle.webtop.core.app.servlet.PublicRequest.java
License:Open Source License
@Override protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebTopApp wta = WebTopApp.get(request); WebTopSession wts = SessionContext.getCurrent(true); try {//www . j a va2s. com String serviceId = ServletUtils.getStringParameter(request, "service", null); String relativePath = null; if (serviceId != null) { // Checks if service ID is valid wts.initPublicEnvironment(request, serviceId); } else { // Retrieves public service ID using its public name String[] urlParts = splitPath(request.getPathInfo()); serviceId = wta.getServiceManager().getServiceIdByPublicName(urlParts[1]); if (serviceId == null) throw new WTRuntimeException("Public name not known [{0}]", urlParts[1]); wts.initPublicEnvironment(request, serviceId); relativePath = urlParts[2]; } // Returns direct stream if pathInfo points to a real file Resource resource = getPublicFile(wta, serviceId, relativePath); if (resource != null) { writeFile(request, response, resource); } else { String action = ServletUtils.getStringParameter(request, "action", false); Boolean nowriter = ServletUtils.getBooleanParameter(request, "nowriter", false); // Retrieves instantiated service BasePublicService instance = wts.getPublicServiceById(serviceId); // Gets method and invokes it... MethodInfo meinfo = getMethod(instance.getClass(), serviceId, action, nowriter); ThreadState threadState = new SubjectThreadState(wta.getAdminSubject()); threadState.bind(); try { invokeMethod(instance, meinfo, serviceId, request, response); } finally { threadState.clear(); } } } catch (Exception ex) { logger.warn("Error processing publicService request", ex); throw new ServletException(ex.getMessage()); } }
From source file:com.sonicle.webtop.core.app.WebTopApp.java
License:Open Source License
void boot() { isStartingUp = true;//w w w . j av a2s . co m ThreadState threadState = new SubjectThreadState(adminSubject); try { threadState.bind(); internalInit(); instance = this; } finally { threadState.clear(); isStartingUp = false; } new Timer("onAppReady").schedule(new TimerTask() { @Override public void run() { ThreadState threadState = new SubjectThreadState(adminSubject); try { LoggerUtils.initDC(); threadState.bind(); onAppReady(); } catch (InterruptedException ex) { // Do nothing... } finally { threadState.clear(); } } }, 5000); }
From source file:com.sonicle.webtop.core.app.WebTopApp.java
License:Open Source License
void shutdown() { isShuttingDown = true;/*www . j a v a 2 s. co m*/ ThreadState threadState = new SubjectThreadState(adminSubject); try { threadState.bind(); internalDestroy(); } finally { threadState.clear(); instance = null; isShuttingDown = false; } }
From source file:com.sonicle.webtop.core.app.WebTopApp.java
License:Open Source License
private void scheduleWebappVersionCheckTask() { long period = 60000; webappVersionCheckTimer = new Timer("webappVersionCheck"); webappVersionCheckTimer.schedule(new TimerTask() { @Override//from www.j a va2 s . com public void run() { ThreadState threadState = new SubjectThreadState(adminSubject); try { threadState.bind(); instance.onWebappVersionCheck(); } finally { threadState.clear(); } } }, period, period); logger.info("Task 'webappVersionCheck' scheduled [{}sec]", period / 1000); }
From source file:com.sonicle.webtop.core.sdk.BaseJobServiceTask.java
License:Open Source License
@Override public final void execute(JobExecutionContext jec) throws JobExecutionException { this.jec = jec; try {// w ww. ja v a 2s.c om LoggerUtils.initDC(); if (!WebTopApp.isShuttingDown()) { if (WebTopApp.getInstance().getServiceManager().canExecuteTaskWork(jec.getJobDetail().getKey())) { Subject subject = ((BaseJobService) getData().get("jobService")).getSubject(); ThreadState threadState = new SubjectThreadState(subject); try { threadState.bind(); executeWork(); } finally { threadState.clear(); } } } } finally { LoggerUtils.clearDC(); } }
From source file:org.apache.geode.internal.cache.tier.sockets.CacheClientProxy.java
License:Apache License
/** * Delivers the message to the client representing this client proxy. * //from w w w .j a v a 2 s .co m * @param conflatable */ protected void deliverMessage(Conflatable conflatable) { ThreadState state = this.securityService.bindSubject(this.subject); ClientUpdateMessage clientMessage = null; if (conflatable instanceof HAEventWrapper) { clientMessage = ((HAEventWrapper) conflatable).getClientUpdateMessage(); } else { clientMessage = (ClientUpdateMessage) conflatable; } this._statistics.incMessagesReceived(); // post process if (this.securityService.needPostProcess()) { Object oldValue = clientMessage.getValue(); Object newValue = securityService.postProcess(clientMessage.getRegionName(), clientMessage.getKeyOfInterest(), oldValue, clientMessage.valueIsObject()); clientMessage.setLatestValue(newValue); } if (clientMessage.needsNoAuthorizationCheck() || postDeliverAuthCheckPassed(clientMessage)) { // If dispatcher is getting initialized, add the event to temporary queue. if (this.messageDispatcherInit) { synchronized (this.queuedEventsSync) { if (this.messageDispatcherInit) { // Check to see value did not changed while getting the // synchronize lock. if (logger.isDebugEnabled()) { logger.debug( "Message dispatcher for proxy {} is getting initialized. Adding message to the queuedEvents.", this); } this.queuedEvents.add(conflatable); return; } } } if (this._messageDispatcher != null) { this._messageDispatcher.enqueueMessage(conflatable); } else { this._statistics.incMessagesFailedQueued(); if (logger.isDebugEnabled()) { logger.debug( "Message is not added to the queue. Message dispatcher for proxy: {} doesn't exist.", this); } } } else { this._statistics.incMessagesFailedQueued(); } if (state != null) state.clear(); }
From source file:org.apache.geode.internal.cache.tier.sockets.ServerConnection.java
License:Apache License
private void doNormalMsg() { Message msg = null;//from ww w . ja va2 s .c o m msg = BaseCommand.readRequest(this); ThreadState threadState = null; try { if (msg != null) { // this.logger.fine("donormalMsg() msgType " + msg.getMessageType()); // Since this thread is not interrupted when the cache server is // shutdown, // test again after a message has been read. This is a bit of a hack. I // think this thread should be interrupted, but currently AcceptorImpl // doesn't keep track of the threads that it launches. if (!this.processMessages || (crHelper.isShutdown())) { if (logger.isDebugEnabled()) { logger.debug("{} ignoring message of type {} from client {} due to shutdown.", getName(), MessageType.getString(msg.getMessageType()), this.proxyId); } return; } if (msg.getMessageType() != MessageType.PING) { // check for invalid number of message parts if (msg.getNumberOfParts() <= 0) { failureCount++; if (failureCount > 3) { this.processMessages = false; return; } else { return; } } } if (logger.isTraceEnabled()) { logger.trace("{} received {} with txid {}", getName(), MessageType.getString(msg.getMessageType()), msg.getTransactionId()); if (msg.getTransactionId() < -1) { // TODO: why is this happening? msg.setTransactionId(-1); } } if (msg.getMessageType() != MessageType.PING) { // we have a real message (non-ping), // so let's call receivedPing to let the CHM know client is busy acceptor.getClientHealthMonitor().receivedPing(this.proxyId); } Command command = getCommand(Integer.valueOf(msg.getMessageType())); if (command == null) { command = Default.getCommand(); } // if a subject exists for this uniqueId, binds the subject to this thread so that we can do // authorization later if (AcceptorImpl.isIntegratedSecurity() && !isInternalMessage() && this.communicationMode != Acceptor.GATEWAY_TO_GATEWAY) { long uniqueId = getUniqueId(); Subject subject = this.clientUserAuths.getSubject(uniqueId); if (subject != null) { threadState = securityService.bindSubject(subject); } } command.execute(msg, this); } } finally { // Keep track of the fact that a message is no longer being // processed. setNotProcessingMessage(); clearRequestMsg(); if (threadState != null) { threadState.clear(); } } }