Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

minor cleanup. Tested.

  • Loading branch information...
commit c30824df34a88dfffc3aa1929cc9daf4df4c9167 1 parent d899db7
Joubin Houshyar alphazero authored
18 core/ri/src/main/java/org/jredis/ri/alphazero/connection/ConnectionBase.java
@@ -37,7 +37,6 @@
37 37 import org.jredis.RedisException;
38 38 import org.jredis.connector.Connection;
39 39 import org.jredis.connector.ConnectionSpec;
40   -import org.jredis.connector.Connection.Property;
41 40 import org.jredis.connector.Connection.Event.Type;
42 41 import org.jredis.protocol.Command;
43 42 import org.jredis.protocol.Protocol;
@@ -64,7 +63,7 @@
64 63 *
65 64 */
66 65
67   -public abstract class ConnectionBase implements Connection {
  66 +public abstract class ConnectionBase implements Connection{
68 67
69 68 // ------------------------------------------------------------------------
70 69 // Properties
@@ -119,12 +118,22 @@ protected ConnectionBase (ConnectionSpec spec)
119 118 catch (Exception e) {
120 119 throw new ProviderException("Unexpected error on initialize -- BUG", e);
121 120 }
122   -
  121 + // TODO: problematic in constructor.
123 122 if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
124 123 connect ();
125 124 }
126 125 }
127   -
  126 + /*
  127 + * TDOD: this is the right way but breaks some assumptions in various impls.
  128 + * - need to add INITIALIZED state and go from there.
  129 + */
  130 +// @Override
  131 +// public void initialize() throws ClientRuntimeException, ProviderException {
  132 +// if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
  133 +// connect ();
  134 +// }
  135 +// }
  136 +
128 137 // ------------------------------------------------------------------------
129 138 // Interface
130 139 // ============================================================ Connection
@@ -197,6 +206,7 @@ protected void initializeComponents () {
197 206 setProtocolHandler (Assert.notNull (newProtocolHandler(), "the delegate protocol handler", ClientRuntimeException.class));
198 207
199 208 if(spec.getConnectionFlag(Connection.Flag.RELIABLE)){
  209 + Log.debug("WARNING: heartbeat is disabled.");
200 210 // heartbeat = new HeartbeatJinn(this, this.spec.getHeartbeat(), " [" + this + "] heartbeat");
201 211 // heartbeat.start();
202 212 }
4 core/ri/src/main/java/org/jredis/ri/alphazero/connection/DefaultConnectionFactory.java
@@ -54,6 +54,10 @@ public Connection newConnection (ConnectionSpec spec)
54 54 // TODO: factories create completed products --
55 55 // this class needs to set conn settings for ALL connection types
56 56 //
  57 +// if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) {
  58 +// ((ConnectionBase)conn).initialize ();
  59 +// }
  60 +
57 61 Log.debug("Created new %s", conn);
58 62 return conn;
59 63 }
1  core/ri/src/main/java/org/jredis/ri/alphazero/connection/DefaultConnectionSpec.java
@@ -18,7 +18,6 @@
18 18 import org.jredis.connector.Connection.Modality;
19 19 import org.jredis.ri.alphazero.protocol.DefaultProtocolFactory;
20 20 import org.jredis.ri.alphazero.support.Assert;
21   -import org.jredis.ri.alphazero.support.Log;
22 21
23 22 /**
24 23 * Default connection spec provides the following default values for a connection. See
43 core/ri/src/main/java/org/jredis/ri/alphazero/connection/SynchConnection.java
@@ -16,6 +16,8 @@
16 16
17 17 package org.jredis.ri.alphazero.connection;
18 18
  19 +import java.util.concurrent.locks.Lock;
  20 +import java.util.concurrent.locks.ReentrantLock;
19 21 import org.jredis.ClientRuntimeException;
20 22 import org.jredis.ProviderException;
21 23 import org.jredis.RedisException;
@@ -46,6 +48,7 @@
46 48 // Properties
47 49 // ------------------------------------------------------------------------
48 50
  51 + final private Lock lock;
49 52
50 53 // ------------------------------------------------------------------------
51 54 // Constructors
@@ -72,6 +75,14 @@ public SynchConnection (
72 75 throws ClientRuntimeException, ProviderException
73 76 {
74 77 super (connectionSpec.setModality(Modality.Synchronous));
  78 + // REVU: huge flaw. connection initialization occurs in constructor!!! stupid.
  79 + // TODO: change it.
  80 + if(spec.getConnectionFlag(Flag.RELIABLE))
  81 + lock = new ReentrantLock(false);
  82 + else{
  83 + lock = null;
  84 + spec.getConnectionFlag(Flag.RELIABLE);
  85 + }
75 86 }
76 87
77 88 // ------------------------------------------------------------------------
@@ -90,12 +101,26 @@ public final Modality getModality() {
90 101 /* (non-Javadoc)
91 102 * @see org.jredis.ri.alphazero.connection.ConnectionBase#serviceRequest(org.jredis.protocol.Command, byte[][])
92 103 */
93   - // TODO: not happy about the performance hit synchronized has caused ... but its required for heartbeat.
94   - // is it worth it?
95   - public synchronized Response serviceRequest (Command cmd, byte[]... args)
  104 + public Response serviceRequest (Command cmd, byte[]... args)
96 105 throws RedisException
  106 +// {
  107 +// Lock _lock = null;
  108 +// if(spec.getConnectionFlag(Flag.RELIABLE))
  109 +// _lock = acquireLock();
  110 +//
  111 +// Response r = null;
  112 +//
  113 +// try { r = _serviceRequest(cmd, args); }
  114 +// catch (Throwable t){ Log.error("serviceRequest cmd:%s %s:=>%s", t, t.getMessage());}
  115 +// finally {
  116 +// if(_lock != null) releaseLock();
  117 +// }
  118 +//
  119 +// return r;
  120 +// }
  121 +// private Response _serviceRequest(Command cmd, byte[]... args)
  122 +// throws RedisException
97 123 {
98   -
99 124 if(!isConnected()) throw new NotConnectedException ("Not connected!");
100 125
101 126 Request request = null;
@@ -137,7 +162,6 @@ public synchronized Response serviceRequest (Command cmd, byte[]... args)
137 162
138 163 throw new ClientRuntimeException("unexpected runtime exeption: " + e.getLocalizedMessage(), e);
139 164 }
140   -
141 165 // 3 - Status
142 166 //
143 167 status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
@@ -152,4 +176,13 @@ else if(status.code() == ResponseStatus.Code.CIAO) {
152 176
153 177 return response;
154 178 }
  179 + @SuppressWarnings("unused")
  180 + private Lock acquireLock() {
  181 + lock.lock();
  182 + return lock;
  183 + }
  184 + @SuppressWarnings("unused")
  185 + private void releaseLock() {
  186 + lock.unlock();
  187 + }
155 188 }

0 comments on commit c30824d

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