Skip to content

Commit

Permalink
AXIS2-4722: Introduced an abstract doInit method in AbstractTransport…
Browse files Browse the repository at this point in the history
…ListenerEx so that derived classes can properly do their initialization stuff before the first endpoint is created.
  • Loading branch information
veithen committed May 23, 2010
1 parent 2907276 commit 1d8233c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 50 deletions.
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.axis2.transport.base;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.AxisFault;

import java.util.ArrayList;
Expand All @@ -36,11 +34,8 @@ public abstract class AbstractPollingTransportListener<T extends AbstractPollTab
private final List<T> endpoints = new ArrayList<T>();

@Override
public void init(ConfigurationContext cfgCtx,
TransportInDescription transportIn) throws AxisFault {

protected void doInit() throws AxisFault {
timer = new Timer("PollTimer");
super.init(cfgCtx, transportIn);
}

@Override
Expand Down
Expand Up @@ -347,6 +347,10 @@ protected void logException(String msg, Exception e) {
log.error(msg, e);
}

public TransportInDescription getTransportInDescription() {
return transportIn;
}

public String getTransportName() {
return transportIn.getName();
}
Expand Down
Expand Up @@ -48,11 +48,13 @@ public abstract class AbstractTransportListenerEx<E extends ProtocolEndpoint>
protected boolean useGlobalListener = false;

@Override
public void init(ConfigurationContext cfgCtx,
public final void init(ConfigurationContext cfgCtx,
TransportInDescription transportIn) throws AxisFault {

super.init(cfgCtx, transportIn);

doInit();

// Create endpoint configured at transport level (if available)
E endpoint = createEndpoint();
endpoint.init(this, null);
Expand All @@ -62,6 +64,15 @@ public void init(ConfigurationContext cfgCtx,
}
}

/**
* Initialize the transport. This method will be called after the initialization work in
* {@link AbstractTransportListener} and before the first endpoint is created, i.e. before the
* first call to {@link #createEndpoint()}.
*
* @throws AxisFault
*/
protected abstract void doInit() throws AxisFault;

@Override
public void destroy() {
// Explicitly stop all endpoints not predispatched to services. All other endpoints will
Expand Down
Expand Up @@ -23,8 +23,6 @@
import java.net.SocketAddress;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.transport.base.AbstractTransportListenerEx;

public abstract class AbstractDatagramTransportListener<E extends DatagramEndpoint>
Expand All @@ -33,19 +31,8 @@ public abstract class AbstractDatagramTransportListener<E extends DatagramEndpoi
private DatagramDispatcher<E> dispatcher;
private String defaultIp;

@Override
public void init(ConfigurationContext cfgCtx, TransportInDescription transportIn)
throws AxisFault {

super.init(cfgCtx, transportIn);
initDispatcher();
}

private void initDispatcher() throws AxisFault {
if (dispatcher != null) {
return;
}

@Override
protected void doInit() throws AxisFault {
DatagramDispatcherCallback callback = new DatagramDispatcherCallback() {

public void receive(SocketAddress address,
Expand Down Expand Up @@ -80,8 +67,6 @@ protected final E createEndpoint() {

@Override
protected void startEndpoint(E endpoint) throws AxisFault {
initDispatcher();

try {
dispatcher.addEndpoint(endpoint);
} catch (IOException ex) {
Expand Down
Expand Up @@ -17,10 +17,8 @@

import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.transport.base.AbstractTransportListenerEx;
import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.base.ManagementSupport;
Expand Down Expand Up @@ -55,18 +53,9 @@ public class JMSListener extends AbstractTransportListenerEx<JMSEndpoint> implem

private final TransportErrorSourceSupport tess = new TransportErrorSourceSupport(this);

/**
* TransportListener initialization
*
* @param cfgCtx the Axis configuration context
* @param trpInDesc the TransportIn description
*/
@Override
public void init(ConfigurationContext cfgCtx,
TransportInDescription trpInDesc) throws AxisFault {

super.init(cfgCtx, trpInDesc);
connFacManager = new JMSConnectionFactoryManager(trpInDesc);
protected void doInit() throws AxisFault {
connFacManager = new JMSConnectionFactoryManager(getTransportInDescription());
log.info("JMS Transport Receiver/Listener initialized...");
}

Expand Down
Expand Up @@ -22,9 +22,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.transport.TransportUtils;
import org.apache.axis2.transport.RequestResponseTransport;
Expand Down Expand Up @@ -68,18 +66,9 @@ public class MailTransportListener extends AbstractPollingTransportListener<Poll

private final TransportErrorSourceSupport tess = new TransportErrorSourceSupport(this);

/**
* Initializes the Mail transport
*
* @param cfgCtx the Axsi2 configuration context
* @param trpInDesc the POP3 transport in description from the axis2.xml
* @throws AxisFault on error
*/
@Override
public void init(ConfigurationContext cfgCtx, TransportInDescription trpInDesc)
throws AxisFault {
super.init(cfgCtx, trpInDesc);

protected void doInit() throws AxisFault {
super.doInit();
// set the synchronise callback table
if (cfgCtx.getProperty(BaseConstants.CALLBACK_TABLE) == null){
cfgCtx.setProperty(BaseConstants.CALLBACK_TABLE, new ConcurrentHashMap());
Expand Down

0 comments on commit 1d8233c

Please sign in to comment.