001: /*
002: * Copyright 2004,2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.axis2.clustering;
017:
018: import org.apache.axis2.handlers.AbstractHandler;
019: import org.apache.axis2.context.MessageContext;
020: import org.apache.axis2.context.ConfigurationContext;
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.description.AxisServiceGroup;
023: import org.apache.axis2.description.Parameter;
024: import org.apache.axis2.description.AxisService;
025: import org.apache.axis2.description.HandlerDescription;
026:
027: /**
028: *
029: */
030: public class RequestBlockingHandler extends AbstractHandler {
031: public InvocationResponse invoke(MessageContext msgContext)
032: throws AxisFault {
033:
034: // Handle blocking at gobal level
035: ConfigurationContext cfgCtx = msgContext
036: .getConfigurationContext();
037: Boolean isBlockingAllRequests = (Boolean) cfgCtx
038: .getProperty(ClusteringConstants.BLOCK_ALL_REQUESTS);
039: AxisServiceGroup serviceGroup = msgContext
040: .getAxisServiceGroup();
041:
042: // Handle blocking at service group level
043: Boolean isBlockingServiceGroupRequests = Boolean.FALSE;
044: if (serviceGroup != null) {
045: Parameter blockingParam = serviceGroup
046: .getParameter(ClusteringConstants.BLOCK_ALL_REQUESTS);
047: if (blockingParam != null) {
048: isBlockingServiceGroupRequests = (Boolean) blockingParam
049: .getValue();
050: }
051: }
052:
053: // Handle blocking at service level
054: AxisService service = msgContext.getAxisService();
055: Boolean isBlockingServiceRequests = Boolean.FALSE;
056: if (service != null) {
057: Parameter blockingParam = service
058: .getParameter(ClusteringConstants.BLOCK_ALL_REQUESTS);
059: if (blockingParam != null) {
060: isBlockingServiceRequests = (Boolean) blockingParam
061: .getValue();
062: }
063: }
064:
065: if (isBlockingAllRequests != null
066: && isBlockingAllRequests.booleanValue()) {
067:
068: // Allow only NodeManager service commit requests to pass through. Block all others
069: AxisService axisService = msgContext.getAxisService();
070: if (!axisService.getName().equals(
071: ClusteringConstants.NODE_MANAGER_SERVICE)) {
072: if (!msgContext.getAxisOperation().getName().equals(
073: "commit")) {
074: throw new AxisFault(
075: "System is being reinitialized. "
076: + "Please try again in a few seconds.");
077: } else {
078: throw new AxisFault(
079: "NodeManager service cannot call any other "
080: + "operation after calling prepare");
081: }
082: }
083: } else if (isBlockingServiceGroupRequests.booleanValue()) {
084: throw new AxisFault(
085: "This service group is being initialized or unloaded. "
086: + "Please try again in a few seconds.");
087: } else if (isBlockingServiceRequests.booleanValue()) {
088: throw new AxisFault("This service is being initialized. "
089: + "Please try again in a few seconds.");
090: }
091: return InvocationResponse.CONTINUE;
092: }
093:
094: public boolean equals(Object obj) {
095: if (obj instanceof RequestBlockingHandler) {
096: RequestBlockingHandler that = (RequestBlockingHandler) obj;
097: HandlerDescription this Desc = this .getHandlerDesc();
098: HandlerDescription thatDesc = that.getHandlerDesc();
099: if (this Desc != null && thatDesc != null
100: && this Desc.getName().equals(thatDesc.getName())) {
101: return true;
102: }
103: }
104: return false;
105: }
106:
107: public int hashCode() {
108: if (this.handlerDesc != null) {
109: return this.handlerDesc.hashCode();
110: }
111: return super.hashCode();
112: }
113: }
|