You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2009/05/01 18:52:20 UTC
svn commit: r770751 [2/2] - in /synapse/trunk/java/modules:
core/src/main/java/org/apache/synapse/
core/src/main/java/org/apache/synapse/config/
core/src/main/java/org/apache/synapse/config/xml/
core/src/main/java/org/apache/synapse/core/axis2/ core/sr...
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java Fri May 1 16:52:18 2009
@@ -109,7 +109,7 @@
protected void buildDataSource(OMElement elem, AbstractDBMediator mediator) {
- OMElement pool = null;
+ OMElement pool;
// get the 'pool' element and determine if we need to create a DataSource or
// look up using JNDI
try {
@@ -143,7 +143,7 @@
String dsName = getValue(pool, DSNAME_Q);
mediator.addDataSourceProperty(DSNAME_Q, dsName);
- DataSource dataSource = null;
+ DataSource dataSource = null;
RepositoryBasedDataSourceFinder finder = RepositoryBasedDataSourceFinder.getInstance();
if (finder.isInitialized()) {
dataSource = RepositoryBasedDataSourceFinder.getInstance().find(dsName);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AnonymousServiceFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AnonymousServiceFactory.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AnonymousServiceFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AnonymousServiceFactory.java Fri May 1 16:52:18 2009
@@ -27,6 +27,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.ServerManager;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.config.SynapseConfiguration;
@@ -199,6 +200,7 @@
if (synapseCallbackReceiver == null) {
synapseCallbackReceiver = new SynapseCallbackReceiver(synCfg);
+ ServerManager.getInstance().setSynapseCallbackReceiver(synapseCallbackReceiver);
}
return synapseCallbackReceiver;
}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2TransportHelper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2TransportHelper.java?rev=770751&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2TransportHelper.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2TransportHelper.java Fri May 1 16:52:18 2009
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.transport.TransportSender;
+import org.apache.axis2.transport.base.ManagementSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * Provides functionality to pause and resume listeners and transports and retrieve
+ * current thread count.
+ */
+public class Axis2TransportHelper {
+
+ private static Log log = LogFactory.getLog(Axis2TransportHelper.class);
+
+ private ConfigurationContext configurationContext;
+
+ /**
+ * Creates a new Axis2TransportHelper using the provided Axis2 configuration context.
+ *
+ * @param configurationContext an Axis2 configuration context
+ */
+ public Axis2TransportHelper(ConfigurationContext configurationContext) {
+ this.configurationContext = configurationContext;
+ }
+
+ /**
+ * Pauses all Axis2 listeners which support this operation.
+ */
+ public void pauseListeners() {
+ if ((configurationContext != null)
+ && (configurationContext.getAxisConfiguration() != null)) {
+
+ Map<String, TransportInDescription> trpIns
+ = configurationContext.getAxisConfiguration().getTransportsIn();
+
+ for (TransportInDescription trpIn : trpIns.values()) {
+ TransportListener trpLst = trpIn.getReceiver();
+ if (trpLst instanceof ManagementSupport) {
+ try {
+ ((ManagementSupport) trpLst).pause();
+ } catch (AxisFault axisFault) {
+ log.error(new StringBuilder("Error putting transport listener for: ")
+ .append(trpIn.getName()).append(" into maintenence").toString());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Resumes all paused Axis2 listeners.
+ */
+ public void resumeListeners() {
+ if ((configurationContext != null)
+ && (configurationContext.getAxisConfiguration() != null)) {
+
+ Map<String, TransportInDescription> trpIns
+ = configurationContext.getAxisConfiguration().getTransportsIn();
+
+ for (TransportInDescription trpIn : trpIns.values()) {
+ TransportListener trpLst = trpIn.getReceiver();
+ if (trpLst instanceof ManagementSupport) {
+ try {
+ ((ManagementSupport) trpLst).resume();
+ } catch (AxisFault axisFault) {
+ log.error(new StringBuilder("Error resuming transport listener for: ")
+ .append(trpIn.getName()).append(" from maintenence").toString());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Pauses all Axis2 senders which support this operation.
+ */
+ public void pauseSenders() {
+ if ((configurationContext != null)
+ && (configurationContext.getAxisConfiguration() != null)) {
+
+ Map<String, TransportOutDescription> trpOuts
+ = configurationContext.getAxisConfiguration().getTransportsOut();
+
+ for (TransportOutDescription trpOut : trpOuts.values()) {
+ TransportSender trpSnd = trpOut.getSender();
+ if (trpSnd instanceof ManagementSupport) {
+ try {
+ ((ManagementSupport) trpSnd).pause();
+ } catch (AxisFault axisFault) {
+ log.error(new StringBuilder("Error pausing transport sender: ")
+ .append(trpOut.getName()).toString());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Resumes all paused Axis2 senders.
+ */
+ public void resumeSenders() {
+ if ((configurationContext != null)
+ && (configurationContext.getAxisConfiguration() != null)) {
+
+ Map<String, TransportOutDescription> trpOuts
+ = configurationContext.getAxisConfiguration().getTransportsOut();
+
+ for (TransportOutDescription trpOut : trpOuts.values()) {
+ TransportSender trpSnd = trpOut.getSender();
+ if (trpSnd instanceof ManagementSupport) {
+ try {
+ ((ManagementSupport) trpSnd).resume();
+ } catch (AxisFault axisFault) {
+ log.error(new StringBuilder("Error resuming transport sender for : ")
+ .append(trpOut.getName()).append(" from maintenence").toString());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Determines the total number of pending listener threads (active + queued).
+ *
+ * @return the total number of pending listener threads (active + queued).
+ */
+ public int getPendingListenerThreadCount() {
+
+ int pendingThreads = 0;
+ Map<String, TransportInDescription> trpIns
+ = configurationContext.getAxisConfiguration().getTransportsIn();
+
+ for (TransportInDescription trpIn : trpIns.values()) {
+ TransportListener trpLst = trpIn.getReceiver();
+
+ if (trpLst instanceof ManagementSupport) {
+ int inUse = ((ManagementSupport) trpLst).getActiveThreadCount();
+ int inQue = ((ManagementSupport) trpLst).getQueueSize();
+
+ if ((inUse + inQue) > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug(new StringBuilder("Transport Listener : ")
+ .append(trpIn.getName()).append(" currently using : ")
+ .append(inUse).append(" threads with ").append(inQue)
+ .append(" requests already queued...").toString());
+ }
+ pendingThreads = (inUse + inQue);
+ }
+ }
+ }
+
+ return pendingThreads;
+ }
+
+ /**
+ * Determines the total number of pending sender threads (active + queued).
+ *
+ * @return the total number of pending sender threads (active + queued).
+ */
+ public int getPendingSenderThreadCount() {
+
+ int pendingThreads = 0;
+ Map<String, TransportOutDescription> trpOuts
+ = configurationContext.getAxisConfiguration().getTransportsOut();
+
+ for (TransportOutDescription trpOut : trpOuts.values()) {
+ TransportSender trpSnd = trpOut.getSender();
+
+ if (trpSnd instanceof ManagementSupport) {
+ int inUse = ((ManagementSupport) trpSnd).getActiveThreadCount();
+ int inQue = ((ManagementSupport) trpSnd).getQueueSize();
+
+ if ((inUse + inQue) > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug(new StringBuilder("Transport Sender : ")
+ .append(trpSnd.getName()).append(" currently using : ")
+ .append(inUse).append(" threads with ").append(inQue)
+ .append(" requests already queued...").toString());
+ }
+ pendingThreads += (inUse + inQue);
+ }
+ }
+ }
+
+ return pendingThreads;
+ }
+}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseAxisServlet.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseAxisServlet.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseAxisServlet.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseAxisServlet.java Fri May 1 16:52:18 2009
@@ -43,7 +43,7 @@
public void init(ServletConfig config) throws ServletException {
ServletContext servletContext = config.getServletContext();
this.configContext = (ConfigurationContext) ServerManager.getInstance().
- getContextInformation().getServerContext();
+ getServerContextInformation().getServerContext();
this.axisConfiguration = this.configContext.getAxisConfiguration();
servletContext.setAttribute(this.getClass().getName(), this);
this.servletConfig = config;
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java Fri May 1 16:52:18 2009
@@ -80,6 +80,9 @@
timeOutTimer.schedule(timeoutHandler, 0, timeoutHandlerInterval);
}
+ public int getCallbackCount() {
+ return callbackStore.size();
+ }
public void addCallback(String MsgID, AxisCallback callback) {
callbackStore.put(MsgID, callback);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseStartUpServlet.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseStartUpServlet.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseStartUpServlet.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseStartUpServlet.java Fri May 1 16:52:18 2009
@@ -20,9 +20,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.ServerManager;
-import org.apache.synapse.ServerConfigurationInformationFactory;
import org.apache.synapse.ServerConfigurationInformation;
+import org.apache.synapse.ServerConfigurationInformationFactory;
+import org.apache.synapse.ServerManager;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -30,7 +30,7 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.*;
+import java.io.IOException;
/**
* When Synapse is deployed on a WAR container, this is the init servlet that kicks off the
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java Fri May 1 16:52:18 2009
@@ -31,15 +31,13 @@
public void onFault(MessageContext synCtx) {
- // is this an actual leaf endpoint
- if (getParentEndpoint() != null) {
- // is this really a fault or a timeout/connection close etc?
- if (isTimeout(synCtx)) {
- getContext().onTimeout();
- } else if (isSuspendFault(synCtx)) {
- getContext().onFault();
- }
+ // is this really a fault or a timeout/connection close etc?
+ if (isTimeout(synCtx)) {
+ getContext().onTimeout();
+ } else if (isSuspendFault(synCtx)) {
+ getContext().onFault();
}
+
// this should be an ignored error if we get here
setErrorOnMessage(synCtx, null, null);
super.onFault(synCtx);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java Fri May 1 16:52:18 2009
@@ -98,7 +98,7 @@
public void init(SynapseEnvironment se) {
if (log.isDebugEnabled()) {
- log.debug("Initializing child mediators");
+ log.debug("Initializing child mediators of mediator : " + getType());
}
for (Mediator mediator : mediators) {
@@ -113,7 +113,7 @@
*/
public void destroy() {
if (log.isDebugEnabled()) {
- log.debug("Destroying child mediators");
+ log.debug("Destroying child mediators of mediator : " + getType());
}
for (Mediator mediator : mediators) {
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java Fri May 1 16:52:18 2009
@@ -39,7 +39,7 @@
* @see TaskJobDetailFactory
*/
public JobDetail createJobDetail(TaskDescription taskDescription, Map<String,
- Object> resources, Class<Job> jobClass) {
+ Object> resources, Class<? extends Job> jobClass) {
if (taskDescription == null) {
throw new SynapseTaskException("Task Description cannot be found.", log);
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java Fri May 1 16:52:18 2009
@@ -98,4 +98,26 @@
taskDescriptionRepository.clear();
taskScheduler.shutDown();
}
+
+ public void pauseAll() {
+ if (taskScheduler != null) {
+ if(taskScheduler.isInitialized()) {
+ try {
+ taskScheduler.pauseAll();
+ } catch (SynapseTaskException ignore) {
+ // This exceptions has already been logged and we don't want to interrupt the flow
+ }
+ }
+ }
+ }
+
+ public void resumeAll() {
+ if (taskScheduler != null) {
+ try {
+ taskScheduler.resumeAll();
+ } catch (SynapseTaskException ignore) {
+ // This exceptions has already been logged and we don't want to interrupt the flow
+ }
+ }
+ }
}
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java Fri May 1 16:52:18 2009
@@ -41,5 +41,5 @@
* otherwise , return null
*/
JobDetail createJobDetail(TaskDescription taskDescription, Map<String,
- Object> resources, Class<Job> jobClass);
+ Object> resources, Class<? extends Job> jobClass);
}
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java Fri May 1 16:52:18 2009
@@ -37,7 +37,10 @@
* scheduler instance
*/
private Scheduler scheduler;
- /* determine whether scheduler has been initialized or not - Ready to schedule a Task or not */
+
+ /**
+ * Determines whether scheduler has been initialized and is ready to schedule a task or not.
+ */
private boolean initialized = false;
/**
@@ -127,6 +130,34 @@
}
/**
+ * Pauses all tasks.
+ *
+ * @throws SynapseTaskException if an error occurs pausing all tasks.
+ */
+ public void pauseAll() {
+
+ try {
+ assertInitialized();
+ assertStarted();
+
+ scheduler.pauseAll();
+ } catch (SchedulerException e) {
+ throw new SynapseTaskException("Error pausing tasks ", e, log);
+ }
+ }
+
+ public void resumeAll() {
+ try {
+ assertInitialized();
+ assertStarted();
+
+ scheduler.resumeAll();
+ } catch (SchedulerException e) {
+ throw new SynapseTaskException("Error resuming tasks ", e, log);
+ }
+ }
+
+ /**
* Schedule a Task
*
* @param taskDescription TaskDescription , an information about Task
@@ -134,7 +165,7 @@
* @param jobClass Quartz job class
*/
public void scheduleTask(TaskDescription taskDescription, Map<String,
- Object> resources, Class jobClass) {
+ Object> resources, Class<? extends Job> jobClass) {
assertInitialized();
assertStarted();
@@ -147,12 +178,6 @@
throw new SynapseTaskException("Job Class can not be found", log);
}
- if (!Job.class.isAssignableFrom(jobClass)) {
- throw new SynapseTaskException("Invalid Job Class : [ Expected " +
- Job.class.getName() + "]" +
- " [ Found " + jobClass.getName() + " ]", log);
- }
-
if (triggerFactory == null) {
throw new SynapseTaskException("TriggerFactory can not be found", log);
}
@@ -249,6 +274,19 @@
" [ Group :" + group + " ]");
}
}
+
+ public int getRunningTaskCount(){
+
+ int runningTasks = 0;
+ try {
+ if (scheduler != null) {
+ runningTasks = scheduler.getCurrentlyExecutingJobs().size();
+ }
+ } catch (SchedulerException e) {
+ log.error("Error querying currently executing jobs", e);
+ }
+ return runningTasks;
+ }
/**
* Sets a Trigger Factory , if it needs to void using default factory
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java Fri May 1 16:52:18 2009
@@ -1,6 +1,22 @@
/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
+
package org.apache.synapse.commons.util;
import org.apache.commons.logging.Log;
@@ -11,6 +27,8 @@
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -38,21 +56,23 @@
try {
String key = toKey(port);
+
+ synchronized (registriesCache) {
+ if (registriesCache.containsKey(key)) {
+ if (log.isDebugEnabled()) {
+ log.debug("There is an RMI registry bound to given port :" + port);
+ }
+ return;
+ }
- if (registriesCache.containsKey(key)) {
- if (log.isDebugEnabled()) {
- log.debug("There is an RMI registry bound to given port :" + port);
+ Registry locateRegistry = LocateRegistry.createRegistry(port);
+ if (locateRegistry == null) {
+ handleException("Unable to create a RMI registry with port : " + port);
}
- return;
- }
- Registry locateRegistry = LocateRegistry.createRegistry(port);
- if (locateRegistry == null) {
- handleException("Unable to create a RMI registry with port : " + port);
+ registriesCache.put(key, locateRegistry);
}
- registriesCache.put(key, locateRegistry);
-
} catch (RemoteException e) {
String msg = "Couldn't create a local registry(RMI) : port " + port +
" already in use.";
@@ -68,14 +88,15 @@
public void removeLocalRegistry(int port) {
String key = toKey(port);
- if (registriesCache.containsKey(key)) {
- removeRegistry(key, registriesCache.get(key));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("There is no RMi registry for port : " + port);
+ synchronized (registriesCache) {
+ if (registriesCache.containsKey(key)) {
+ removeRegistry(key, registriesCache.get(key));
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("There is no RMi registry for port : " + port);
+ }
}
}
-
}
/**
@@ -83,10 +104,13 @@
*/
public void shutDown() {
- for (String key : registriesCache.keySet()) {
- removeRegistry(key, registriesCache.get(key));
+ synchronized (registriesCache) {
+ Collection<String> registryKeys = new ArrayList<String>(registriesCache.size());
+ registryKeys.addAll(registriesCache.keySet());
+ for (String key : registryKeys) {
+ removeRegistry(key, registriesCache.get(key));
+ }
}
- registriesCache.clear();
}
/**
@@ -95,16 +119,20 @@
* @param key The port of the RMI registry to be removed
* @param registry Registry instance
*/
- private static void removeRegistry(String key, Registry registry) {
+ private void removeRegistry(String key, Registry registry) {
if (registry != null) {
- try {
- log.info("Removing the RMI registry bound to port : " + key);
- UnicastRemoteObject.unexportObject(registry, true);
- } catch (NoSuchObjectException e) {
- String msg = "Error when stopping localregistry(RMI)";
- handleException(msg, e);
+ synchronized (registriesCache) {
+ try {
+ log.info("Removing the RMI registry bound to port : " + key);
+ UnicastRemoteObject.unexportObject(registry, true);
+ registriesCache.remove(key);
+ } catch (NoSuchObjectException e) {
+ String msg = "Error when stopping localregistry(RMI)";
+ handleException(msg, e);
+ }
}
+
}
}
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java Fri May 1 16:52:18 2009
@@ -1,4 +1,4 @@
-/*
+/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,12 +18,6 @@
*/
package org.apache.synapse.commons.util.datasource;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.commons.util.SynapseUtilException;
import org.apache.synapse.commons.util.datasource.factory.DataSourceInformationRepositoryFactory;
import java.util.Properties;
@@ -33,99 +27,34 @@
*/
public class DataSourceInformationRepositoryHelper {
- private static final Log log = LogFactory.getLog(DataSourceInformationRepositoryHelper.class);
-
/**
- * Initialize and register DataSourceInformationRepository with AxisConfiguration
+ * Initialize DataSourceInformationRepository.
*
- * @param axisConfiguration AxisConfiguration instance
- * @param properties DataSources configuration properties
+ * @param datasourceInformationRepository to be initialized
+ * @param properties DataSources configuration properties
+ *
+ * @return the initialized datasource information repository
*/
- public static void initializeDataSourceInformationRepository(
- AxisConfiguration axisConfiguration, Properties properties) {
-
- DataSourceInformationRepository repository =
- getDataSourceInformationRepository(axisConfiguration);
- DataSourceInformationRepositoryListener listener = null;
+ public static DataSourceInformationRepository initializeDataSourceInformationRepository(
+ DataSourceInformationRepository datasourceInformationRepository,
+ Properties properties) {
- if (repository != null) {
- listener = repository.getRepositoryListener();
- }
-
- if (listener == null) {
- if (log.isDebugEnabled()) {
- log.debug("Creating a new DataSourceInformationRepositoryListener instance ");
- }
- listener = DataSourceRepositoryManager.getInstance();
- }
+ DataSourceInformationRepositoryListener repositoryListener =
+ DataSourceRepositoryManager.getInstance();
- if (listener instanceof DataSourceRepositoryManager) {
+ if (repositoryListener instanceof DataSourceRepositoryManager) {
RepositoryBasedDataSourceFinder finder = RepositoryBasedDataSourceFinder.getInstance();
- finder.init((DataSourceRepositoryManager) listener);
+ finder.init((DataSourceRepositoryManager) repositoryListener);
}
- if (repository == null) {
- if (log.isDebugEnabled()) {
- log.debug("Initiating a new DataSourceInformationRepository");
- }
- initializeDataSourceInformationRepository(axisConfiguration, properties, listener);
- }
- }
-
- /**
- * Initialize and register DataSourceInformationRepository with AxisConfiguration
- *
- * @param axisConfiguration AxisConfiguration instance
- * @param properties DataSources configuration properties
- * @param listener DataSourceInformationRepositoryListener instance
- */
- public static void initializeDataSourceInformationRepository(
- AxisConfiguration axisConfiguration,
- Properties properties,
- DataSourceInformationRepositoryListener listener) {
-
- DataSourceInformationRepository repository =
+ if (datasourceInformationRepository == null) {
+ datasourceInformationRepository =
DataSourceInformationRepositoryFactory.createDataSourceInformationRepository(
- properties, listener);
- Parameter parameter = new Parameter(
- DataSourceConfigurationConstants.DATASOURCE_INFORMATION_REPOSITORY, repository);
- try {
- axisConfiguration.addParameter(parameter);
- } catch (AxisFault axisFault) {
- handleException("Error setting 'DataSourceInformationRepository' as" +
- " a parameter to axis2 configuration ", axisFault);
- }
- }
-
- /**
- * Gets DataSourceInformationRepository that is kept in AxisConfiguration
- *
- * @param axisConfiguration AxisConfiguration instance
- * @return DataSourceInformationRepository instance if there any , otherwise null
- */
- public static DataSourceInformationRepository getDataSourceInformationRepository(
- AxisConfiguration axisConfiguration) {
-
- Parameter parameter = axisConfiguration.getParameter(
- DataSourceConfigurationConstants.DATASOURCE_INFORMATION_REPOSITORY);
- if (parameter != null) {
- Object result = parameter.getValue();
- if (!(result instanceof DataSourceInformationRepository)) {
- handleException("Invalid type '" + result.getClass().getName()
- + "' , expected : 'DataSourceInformationRepository'");
- }
- return (DataSourceInformationRepository) result;
+ repositoryListener, properties);
+ } else {
+ DataSourceInformationRepositoryFactory.setupDatasourceInformationRepository(
+ datasourceInformationRepository, properties);
}
- return null;
- }
-
- private static void handleException(String msg, Throwable error) {
- log.error(msg, error);
- throw new SynapseUtilException(msg, error);
- }
-
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseUtilException(msg);
+ return datasourceInformationRepository;
}
}
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java?rev=770751&r1=770750&r2=770751&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java Fri May 1 16:52:18 2009
@@ -18,6 +18,8 @@
*/
package org.apache.synapse.commons.util.datasource.factory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.util.datasource.DataSourceInformation;
import org.apache.synapse.commons.util.datasource.DataSourceInformationRepository;
import org.apache.synapse.commons.util.datasource.DataSourceInformationRepositoryListener;
@@ -31,6 +33,8 @@
*/
public class DataSourceInformationRepositoryFactory {
+ private static final Log log = LogFactory.getLog(DataSourceInformationRepositoryFactory.class);
+
/**
* Factory method to create a DataSourceInformationRepository
* Use 'DataSourceRepositoryManager' as RepositoryListener
@@ -41,32 +45,54 @@
public static DataSourceInformationRepository createDataSourceInformationRepository(
Properties properties) {
- return createDataSourceInformationRepository(properties,
- DataSourceRepositoryManager.getInstance());
+ return createDataSourceInformationRepository(
+ DataSourceRepositoryManager.getInstance(), properties);
}
/**
* Factory method to create a DataSourceInformationRepository
*
- * @param properties DataSource properties
* @param listener DataSourceInformationRepositoryListener
- * @return DataSourceInformationRepository instance
+ * @param properties DataSource properties
+ *
+ * @return a new, configured DataSourceInformationRepository instance
*/
public static DataSourceInformationRepository createDataSourceInformationRepository(
- Properties properties, DataSourceInformationRepositoryListener listener) {
+ DataSourceInformationRepositoryListener listener, Properties properties) {
- List<DataSourceInformation> sourceInformationList =
- DataSourceInformationListFactory.createDataSourceInformationList(properties);
- DataSourceInformationRepository repository = new DataSourceInformationRepository();
- repository.setRepositoryListener(listener);
+ if (log.isDebugEnabled()) {
+ log.debug("Creating a new DataSourceInformationRepository");
+ }
+ DataSourceInformationRepository datasourceInformationRepository =
+ new DataSourceInformationRepository();
+
+ datasourceInformationRepository.setRepositoryListener(listener);
+ setupDatasourceInformationRepository(datasourceInformationRepository, properties);
+
+ return datasourceInformationRepository;
+ }
+
+ /**
+ * Setup an existing datasource inforamtion repository adding the provided
+ * datasource information.
+ *
+ * @param datasourceInformationRepository an existing data source information repository
+ * @param properties DataSource properties
+ */
+ public static void setupDatasourceInformationRepository(
+ DataSourceInformationRepository datasourceInformationRepository,
+ Properties properties) {
+
if (properties != null && !properties.isEmpty()) {
- repository.setConfigurationProperties(properties);
+ datasourceInformationRepository.setConfigurationProperties(properties);
}
+ List<DataSourceInformation> sourceInformationList =
+ DataSourceInformationListFactory.createDataSourceInformationList(properties);
+
for (DataSourceInformation information : sourceInformationList) {
if (information != null) {
- repository.addDataSourceInformation(information);
+ datasourceInformationRepository.addDataSourceInformation(information);
}
}
- return repository;
}
}