Skip to content
Browse files

minor cleanup. Tested.

  • Loading branch information...
1 parent d899db7 commit c30824df34a88dfffc3aa1929cc9daf4df4c9167 @alphazero alphazero committed Sep 17, 2010
View
18 core/ri/src/main/java/org/jredis/ri/alphazero/connection/ConnectionBase.java
@@ -37,7 +37,6 @@
import org.jredis.RedisException;
import org.jredis.connector.Connection;
import org.jredis.connector.ConnectionSpec;
-import org.jredis.connector.Connection.Property;
import org.jredis.connector.Connection.Event.Type;
import org.jredis.protocol.Command;
import org.jredis.protocol.Protocol;
@@ -64,7 +63,7 @@
*
*/
-public abstract class ConnectionBase implements Connection {
+public abstract class ConnectionBase implements Connection{
// ------------------------------------------------------------------------
// Properties
@@ -119,12 +118,22 @@ protected ConnectionBase (ConnectionSpec spec)
catch (Exception e) {
throw new ProviderException("Unexpected error on initialize -- BUG", e);
}
-
+ // TODO: problematic in constructor.
if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
connect ();
}
}
-
+ /*
+ * TDOD: this is the right way but breaks some assumptions in various impls.
+ * - need to add INITIALIZED state and go from there.
+ */
+// @Override
+// public void initialize() throws ClientRuntimeException, ProviderException {
+// if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
+// connect ();
+// }
+// }
+
// ------------------------------------------------------------------------
// Interface
// ============================================================ Connection
@@ -197,6 +206,7 @@ protected void initializeComponents () {
setProtocolHandler (Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class));
if(spec.getConnectionFlag(Connection.Flag.RELIABLE)){
+ Log.debug("WARNING: heartbeat is disabled.");
// heartbeat = new HeartbeatJinn(this, this.spec.getHeartbeat(), " [" + this + "] heartbeat");
// heartbeat.start();
}
View
4 core/ri/src/main/java/org/jredis/ri/alphazero/connection/DefaultConnectionFactory.java
@@ -54,6 +54,10 @@ public Connection newConnection (ConnectionSpec spec)
// TODO: factories create completed products --
// this class needs to set conn settings for ALL connection types
//
+// if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
+// ((ConnectionBase)conn).initialize ();
+// }
+
Log.debug("Created new %s", conn);
return conn;
}
View
1 core/ri/src/main/java/org/jredis/ri/alphazero/connection/DefaultConnectionSpec.java
@@ -18,7 +18,6 @@
import org.jredis.connector.Connection.Modality;
import org.jredis.ri.alphazero.protocol.DefaultProtocolFactory;
import org.jredis.ri.alphazero.support.Assert;
-import org.jredis.ri.alphazero.support.Log;
/**
* Default connection spec provides the following default values for a connection. See
View
43 core/ri/src/main/java/org/jredis/ri/alphazero/connection/SynchConnection.java
@@ -16,6 +16,8 @@
package org.jredis.ri.alphazero.connection;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.jredis.ClientRuntimeException;
import org.jredis.ProviderException;
import org.jredis.RedisException;
@@ -46,6 +48,7 @@
// Properties
// ------------------------------------------------------------------------
+ final private Lock lock;
// ------------------------------------------------------------------------
// Constructors
@@ -72,6 +75,14 @@ public SynchConnection (
throws ClientRuntimeException, ProviderException
{
super (connectionSpec.setModality(Modality.Synchronous));
+ // REVU: huge flaw. connection initialization occurs in constructor!!! stupid.
+ // TODO: change it.
+ if(spec.getConnectionFlag(Flag.RELIABLE))
+ lock = new ReentrantLock(false);
+ else{
+ lock = null;
+ spec.getConnectionFlag(Flag.RELIABLE);
+ }
}
// ------------------------------------------------------------------------
@@ -90,12 +101,26 @@ public final Modality getModality() {
/* (non-Javadoc)
* @see org.jredis.ri.alphazero.connection.ConnectionBase#serviceRequest(org.jredis.protocol.Command, byte[][])
*/
- // TODO: not happy about the performance hit synchronized has caused ... but its required for heartbeat.
- // is it worth it?
- public synchronized Response serviceRequest (Command cmd, byte[]... args)
+ public Response serviceRequest (Command cmd, byte[]... args)
throws RedisException
+// {
+// Lock _lock = null;
+// if(spec.getConnectionFlag(Flag.RELIABLE))
+// _lock = acquireLock();
+//
+// Response r = null;
+//
+// try { r = _serviceRequest(cmd, args); }
+// catch (Throwable t){ Log.error("serviceRequest cmd:%s %s:=>%s", t, t.getMessage());}
+// finally {
+// if(_lock != null) releaseLock();
+// }
+//
+// return r;
+// }
+// private Response _serviceRequest(Command cmd, byte[]... args)
+// throws RedisException
{
-
if(!isConnected()) throw new NotConnectedException ("Not connected!");
Request request = null;
@@ -137,7 +162,6 @@ public synchronized Response serviceRequest (Command cmd, byte[]... args)
throw new ClientRuntimeException("unexpected runtime exeption: " + e.getLocalizedMessage(), e);
}
-
// 3 - Status
//
status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
@@ -152,4 +176,13 @@ else if(status.code() == ResponseStatus.Code.CIAO) {
return response;
}
+ @SuppressWarnings("unused")
+ private Lock acquireLock() {
+ lock.lock();
+ return lock;
+ }
+ @SuppressWarnings("unused")
+ private void releaseLock() {
+ lock.unlock();
+ }
}

0 comments on commit c30824d

Please sign in to comment.
Something went wrong with that request. Please try again.