configurationcontext.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 765 行 · 第 1/2 页
JAVA
765 行
String valueOperationName;
String valueServiceName;
String valueServiceGroupName;
if (value != null) {
valueOperationName = value.getOperationName();
valueServiceName = value.getServiceName();
valueServiceGroupName = value.getServiceGroupName();
if ((valueOperationName != null) && (valueOperationName.equals(operationName))) {
if ((valueServiceName != null) && (valueServiceName.equals(serviceName))) {
if ((valueServiceGroupName != null) && (serviceGroupName != null)
&& (valueServiceGroupName.equals(serviceGroupName))) {
// match
return value;
}
// or, both need to be null
if ((valueServiceGroupName == null) && (serviceGroupName == null)) {
// match
return value;
}
}
}
}
}
}
// if we got here, we did not find an operation context
// that fits the criteria
return null;
}
/**
* Create a MessageContext, and notify any registered ContextListener.
*
* @return a new MessageContext
*/
public MessageContext createMessageContext() {
MessageContext msgCtx = new MessageContext(this);
contextCreated(msgCtx);
return msgCtx;
}
/**
* Create a ServiceGroupContext for the specified service group, and notify any
* registered ContextListener.
*
* @param serviceGroup an AxisServiceGroup
* @return a new ServiceGroupContext
*/
public ServiceGroupContext createServiceGroupContext(AxisServiceGroup serviceGroup) {
ServiceGroupContext sgCtx = new ServiceGroupContext(this, serviceGroup);
contextCreated(sgCtx);
return sgCtx;
}
/**
* Allows users to resolve the path relative to the root diretory.
*
* @param path
* @return
*/
public File getRealPath(String path) {
URL repository = axisConfiguration.getRepository();
if (repository != null) {
File repo = new File(repository.getFile());
return new File(repo, path);
}
return null;
}
public ServiceGroupContext getServiceGroupContextFromSoapSessionTable(
String serviceGroupContextId,
MessageContext msgContext) throws AxisFault {
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) serviceGroupContextMap.get(serviceGroupContextId);
if (serviceGroupContext != null) {
serviceGroupContext.touch();
return serviceGroupContext;
} else {
throw new AxisFault("Unable to find corresponding context" +
" for the serviceGroupId: " + serviceGroupContextId);
}
}
/**
* Returns a ServiceGroupContext object associated
* with the specified ID from the internal table.
*
* @param serviceGroupCtxId The ID string associated with the ServiceGroupContext object
* @return The ServiceGroupContext object, or null if not found
*/
public ServiceGroupContext getServiceGroupContext(String serviceGroupCtxId) {
if (serviceGroupCtxId == null) {
// Hashtables require non-null key-value pairs
return null;
}
ServiceGroupContext serviceGroupContext = null;
if (serviceGroupContextMap != null) {
serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap.get(serviceGroupCtxId);
if (serviceGroupContext != null) {
serviceGroupContext.touch();
} else {
serviceGroupContext =
(ServiceGroupContext) applicationSessionServiceGroupContexts.get(serviceGroupCtxId);
if (serviceGroupContext != null) {
serviceGroupContext.touch();
}
}
}
return serviceGroupContext;
}
/**
* Gets all service groups in the system.
*
* @return Returns hashmap of ServiceGroupContexts.
*/
public String[] getServiceGroupContextIDs() {
String[] ids = new String[serviceGroupContextMap.size() +
applicationSessionServiceGroupContexts.size()];
int index = 0;
for (Iterator iter = serviceGroupContextMap.keySet().iterator(); iter.hasNext();) {
ids[index] = (String) iter.next();
index++;
}
for (Iterator iter = applicationSessionServiceGroupContexts.keySet().iterator();
iter.hasNext();) {
ids[index] = (String) iter.next();
index++;
}
return ids;
}
/**
* @return The ServiceGroupContexts
* @deprecated Use {@link #getServiceGroupContextIDs} & {@link #getServiceGroupContext(String)}
*/
public Hashtable getServiceGroupContexts() {
return serviceGroupContextMap;
}
/**
* Returns the thread factory.
*
* @return Returns configuration specific thread pool
*/
public ThreadFactory getThreadPool() {
if (threadPool == null) {
threadPool = new ThreadPool();
}
return threadPool;
}
/**
* @param configuration
*/
public void setAxisConfiguration(AxisConfiguration configuration) {
axisConfiguration = configuration;
}
/**
* Sets the thread factory.
*
* @param pool The thread pool
* @throws AxisFault If a thread pool has already been set
*/
public void setThreadPool(ThreadFactory pool) throws AxisFault {
if (threadPool == null) {
threadPool = pool;
} else {
throw new AxisFault(Messages.getMessage("threadpoolset"));
}
}
/**
* Remove a ServiceGroupContext
*
* @param serviceGroupContextId The ID of the ServiceGroupContext
*/
public void removeServiceGroupContext(String serviceGroupContextId) {
if (serviceGroupContextMap == null) {
return;
}
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) serviceGroupContextMap.get(serviceGroupContextId);
serviceGroupContextMap.remove(serviceGroupContextId);
cleanupServiceContexts(serviceGroupContext);
}
private void cleanupServiceGroupContexts() {
if (serviceGroupContextMap == null) {
return;
}
long currentTime = new Date().getTime();
for (Iterator sgCtxtMapKeyIter = serviceGroupContextMap.keySet().iterator();
sgCtxtMapKeyIter.hasNext();) {
String sgCtxtId = (String) sgCtxtMapKeyIter.next();
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) serviceGroupContextMap.get(sgCtxtId);
if ((currentTime - serviceGroupContext.getLastTouchedTime()) >
getServiceGroupContextTimoutInterval()) {
sgCtxtMapKeyIter.remove();
cleanupServiceContexts(serviceGroupContext);
contextRemoved(serviceGroupContext);
}
}
}
public ListenerManager getListenerManager() {
return listenerManager;
}
public void setTransportManager(ListenerManager listenerManager) {
this.listenerManager = listenerManager;
}
private void cleanupServiceContexts(ServiceGroupContext serviceGroupContext) {
if (serviceGroupContext == null) {
return;
}
Iterator serviceContextIter = serviceGroupContext.getServiceContexts();
if (serviceContextIter == null) {
return;
}
while (serviceContextIter.hasNext()) {
ServiceContext serviceContext = (ServiceContext) serviceContextIter.next();
DependencyManager.destroyServiceObject(serviceContext);
}
}
public void cleanupContexts() {
if ((applicationSessionServiceGroupContexts != null) &&
(applicationSessionServiceGroupContexts.size() > 0)) {
for (Iterator applicationScopeSgs =
applicationSessionServiceGroupContexts.values().iterator();
applicationScopeSgs.hasNext();) {
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) applicationScopeSgs.next();
cleanupServiceContexts(serviceGroupContext);
}
applicationSessionServiceGroupContexts.clear();
}
if ((serviceGroupContextMap != null) && (serviceGroupContextMap.size() > 0)) {
for (Iterator soapSessionSgs = serviceGroupContextMap.values().iterator();
soapSessionSgs.hasNext();) {
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) soapSessionSgs.next();
cleanupServiceContexts(serviceGroupContext);
}
serviceGroupContextMap.clear();
}
}
public void terminate() throws AxisFault {
if (listenerManager != null) {
listenerManager.stop();
}
axisConfiguration.cleanup();
cleanupTemp();
}
/**
* This include all the major changes we have done from 1.2
* release to 1.3 release. This will include API changes , class
* deprecating etc etc.
*/
private void cleanupTemp() {
File tempFile = (File) axisConfiguration.getParameterValue(
Constants.Configuration.ARTIFACTS_TEMP_DIR);
if (tempFile == null) {
tempFile = new File(System.getProperty("java.io.tmpdir"), "_axis2");
}
deleteTempFiles(tempFile);
}
private void deleteTempFiles(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
deleteTempFiles(new File(dir, children[i]));
}
}
dir.delete();
}
public String getServiceContextPath() {
if (cachedServicePath == null) {
cachedServicePath = internalGetServiceContextPath();
}
return cachedServicePath;
}
private String internalGetServiceContextPath() {
String ctxRoot = getContextRoot();
String path = "/";
if (ctxRoot != null) {
if (!ctxRoot.equals("/")) {
path = ctxRoot + "/";
}
if (servicePath == null || servicePath.trim().length() == 0) {
throw new IllegalArgumentException("service path cannot be null or empty");
} else {
path += servicePath.trim();
}
}
return path;
}
public String getServicePath() {
if (servicePath == null || servicePath.trim().length() == 0) {
throw new IllegalArgumentException("service path cannot be null or empty");
}
return servicePath.trim();
}
public void setServicePath(String servicePath) {
this.servicePath = servicePath;
}
public String getContextRoot() {
return contextRoot;
}
public void setContextRoot(String contextRoot) {
if (contextRoot != null) {
this.contextRoot = contextRoot.trim(); // Trim before storing away for good hygiene
cachedServicePath = internalGetServiceContextPath();
}
}
/**
* This will be used to fetch the serviceGroupContextTimoutInterval from any place available.
*
* @return long
*/
public long getServiceGroupContextTimoutInterval() {
Integer serviceGroupContextTimoutIntervalParam =
(Integer) getProperty(Constants.Configuration.CONFIG_CONTEXT_TIMOUT_INTERVAL);
if (serviceGroupContextTimoutIntervalParam != null) {
serviceGroupContextTimoutInterval = serviceGroupContextTimoutIntervalParam.intValue();
}
return serviceGroupContextTimoutInterval;
}
public void removeServiceGroupContext(AxisServiceGroup serviceGroup) {
if (serviceGroup != null) {
Object obj = applicationSessionServiceGroupContexts.get(
serviceGroup.getServiceGroupName());
if (obj == null) {
ArrayList toBeRemovedList = new ArrayList();
Iterator serviceGroupContexts = serviceGroupContextMap.values().iterator();
while (serviceGroupContexts.hasNext()) {
ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) serviceGroupContexts.next();
if (serviceGroupContext.getDescription().equals(serviceGroup)) {
toBeRemovedList.add(serviceGroupContext.getId());
}
}
for (int i = 0; i < toBeRemovedList.size(); i++) {
String s = (String) toBeRemovedList.get(i);
serviceGroupContextMap.remove(s);
}
}
}
}
public ConfigurationContext getRootContext() {
return this;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?