AMQP-58 - Support for caching of OtpConnections

This commit is contained in:
markpollack
2010-09-27 15:07:02 -04:00
parent 2974d9fb62
commit cb9f64a5e3
9 changed files with 80 additions and 24 deletions

View File

@@ -31,6 +31,6 @@ import com.ericsson.otp.erlang.OtpConnection;
*/
public interface ConnectionFactory {
OtpConnection createConnection() throws UnknownHostException, OtpAuthException, IOException;
Connection createConnection() throws UnknownHostException, OtpAuthException, IOException;
}

View File

@@ -20,8 +20,6 @@ package org.springframework.erlang.connection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.ericsson.otp.erlang.OtpConnection;
/**
* @author Mark Pollack
*/
@@ -33,7 +31,7 @@ public class ConnectionFactoryUtils {
/**
* Release the given Connection by closing it.
*/
public static void releaseConnection(OtpConnection con, ConnectionFactory cf) {
public static void releaseConnection(Connection con, ConnectionFactory cf) {
if (con == null) {
return;
}

View File

@@ -24,11 +24,18 @@ import org.springframework.erlang.OtpIOException;
import org.springframework.util.Assert;
import com.ericsson.otp.erlang.OtpAuthException;
import com.ericsson.otp.erlang.OtpConnection;
import com.ericsson.otp.erlang.OtpPeer;
import com.ericsson.otp.erlang.OtpSelf;
/**
* A simple implementation of {@link ConnectionFactory} that return a new connection
* for each invocation of the createConnection method.
*
* Note that use of this ConnectionFactory with ErlangTemplate has unstable behavior when
* invoked frequently and will be deprecated. See {@link SingleConnectionFactory} for an
* alternative implementation.
*
*
* Provides a more traditional API to creating a connection to a remote erlang node than
* the JInterface API.
*
@@ -91,9 +98,9 @@ public class SimpleConnectionFactory implements ConnectionFactory, InitializingB
}
public OtpConnection createConnection() throws UnknownHostException, OtpAuthException, IOException {
public Connection createConnection() throws UnknownHostException, OtpAuthException, IOException {
try {
return otpSelf.connect(otpPeer);
return new DefaultConnection(otpSelf.connect(otpPeer));
}
catch (IOException ex) {
throw new OtpIOException("failed to connect from '" + this.selfNodeName

View File

@@ -16,7 +16,7 @@
package org.springframework.erlang.core;
import com.ericsson.otp.erlang.OtpConnection;
import org.springframework.erlang.connection.Connection;
/**
* Basic callback for use in ErlangTemplate
@@ -28,6 +28,6 @@ public interface ConnectionCallback<T> {
* Execute any number of operations against the supplied OTP connection,
* possibly returning a result.
*/
T doInConnection(OtpConnection connection) throws Exception; //Not sure everything it throws
T doInConnection(Connection connection) throws Exception; //Not sure everything it throws
}

View File

@@ -19,6 +19,7 @@ package org.springframework.erlang.core;
import org.springframework.erlang.ErlangBadRpcException;
import org.springframework.erlang.ErlangErrorRpcException;
import org.springframework.erlang.OtpException;
import org.springframework.erlang.connection.Connection;
import org.springframework.erlang.connection.ConnectionFactory;
import org.springframework.erlang.support.ErlangAccessor;
import org.springframework.erlang.support.ErlangUtils;
@@ -44,7 +45,7 @@ public class ErlangTemplate extends ErlangAccessor implements ErlangOperations {
public OtpErlangObject executeErlangRpc(final String module, final String function, final OtpErlangList args) {
return execute(new ConnectionCallback<OtpErlangObject>() {
public OtpErlangObject doInConnection(OtpConnection connection) throws Exception {
public OtpErlangObject doInConnection(Connection connection) throws Exception {
logger.debug("Sending RPC for module [" + module + "] function [" + function + "] args [" + args);
connection.sendRPC(module, function, args);
//TODO consider dedicated response object.
@@ -109,7 +110,7 @@ public class ErlangTemplate extends ErlangAccessor implements ErlangOperations {
public <T> T execute(ConnectionCallback<T> action) throws OtpException {
Assert.notNull(action, "Callback object must not be null");
OtpConnection con = null;
Connection con = null;
try {
con = createConnection();
return action.doInConnection(con);

View File

@@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.erlang.OtpException;
import org.springframework.erlang.connection.Connection;
import org.springframework.erlang.connection.ConnectionFactory;
import com.ericsson.otp.erlang.OtpAuthException;
@@ -39,7 +40,7 @@ public abstract class ErlangAccessor implements InitializingBean {
private ConnectionFactory connectionFactory;
protected OtpConnection createConnection() throws UnknownHostException, OtpAuthException, IOException {
protected Connection createConnection() throws UnknownHostException, OtpAuthException, IOException {
return getConnectionFactory().createConnection();
}