Hiram R. Chirino 2006-03-03 21:24:33 +00:00
parent 44b00e9309
commit 202b3efb96
2 changed files with 11 additions and 29 deletions

View File

@ -29,14 +29,14 @@ import javax.resource.spi.endpoint.MessageEndpoint;
public class MessageEndpointProxy implements MessageListener, MessageEndpoint {
private static final MessageEndpointState ALIVE = new MessageEndpointAlive();
private static final MessageEndpointState GOING_TO_DIE = new MessageEndpointInTheElectricChair();
private static final MessageEndpointState DEAD = new MessageEndpointDead();
private static int proxyCount = 0;
private final int proxyID;
private MessageEndpoint endpoint;
private final MessageEndpoint endpoint;
private final MessageListener messageListener;
private MessageEndpointState state = ALIVE;
private static int getID() {
@ -47,6 +47,7 @@ public class MessageEndpointProxy implements MessageListener, MessageEndpoint {
if (!(endpoint instanceof MessageListener)) {
throw new IllegalArgumentException("MessageEndpoint is not a MessageListener");
}
messageListener = (MessageListener) endpoint;
proxyID = getID();
this.endpoint = endpoint;
}
@ -56,7 +57,6 @@ public class MessageEndpointProxy implements MessageListener, MessageEndpoint {
}
public void onMessage(Message message) {
// log.warn("Delivery Count: " + getNextDeliveryCount() );
state.onMessage(this, message);
}
@ -117,12 +117,7 @@ public class MessageEndpointProxy implements MessageListener, MessageEndpoint {
}
public void onMessage(MessageEndpointProxy proxy, Message message) {
try {
((MessageListener) proxy.endpoint).onMessage(message);
} catch (RuntimeException e) {
transition(proxy, GOING_TO_DIE);
throw e;
}
proxy.messageListener.onMessage(message);
}
public void afterDelivery(MessageEndpointProxy proxy) throws ResourceException {
@ -139,28 +134,10 @@ public class MessageEndpointProxy implements MessageListener, MessageEndpoint {
}
}
private static class MessageEndpointInTheElectricChair extends MessageEndpointState {
public void afterDelivery(MessageEndpointProxy proxy) throws ResourceException {
try {
proxy.endpoint.afterDelivery();
} catch (ResourceException e) {
throw e;
} finally {
transition(proxy, DEAD);
}
}
public void release(MessageEndpointProxy proxy) {
transition(proxy, DEAD);
}
}
private static class MessageEndpointDead extends MessageEndpointState {
protected void enter(MessageEndpointProxy proxy) {
proxy.endpoint.release();
proxy.endpoint = null;
}
public void beforeDelivery(MessageEndpointProxy proxy, Method method) throws NoSuchMethodException, ResourceException {

View File

@ -76,6 +76,7 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
} catch (UnavailableException e) {
// The container could be limiting us on the number of endpoints
// that are being created.
log.debug("Could not create an endpoint.", e);
session.close();
return null;
}
@ -104,15 +105,19 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
} else {
// Are we at the upper limit?
if (activeSessions.size() >= maxSessions) {
// then reuse the allready created sessions..
// then reuse the already created sessions..
// This is going to queue up messages into a session for
// processing.
return getExistingServerSession();
}
ServerSessionImpl ss = createServerSessionImpl();
// We may not be able to create a session due to the conatiner
// We may not be able to create a session due to the container
// restricting us.
if (ss == null) {
if (idleSessions.size() == 0) {
throw new JMSException("Endpoint factory did not allows to any endpoints.");
}
return getExistingServerSession();
}
activeSessions.addLast(ss);