You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2007/01/10 22:47:31 UTC
svn commit: r495000 - in /incubator/qpid/branches/qpid.0-9/java:
broker/src/main/java/org/apache/qpid/server/protocol/
client/src/main/java/org/apache/qpid/client/protocol/
common/src/main/java/org/apache/qpid/framing/
common/src/main/java/org/apache/q...
Author: kpvdr
Date: Wed Jan 10 13:47:30 2007
New Revision: 495000
URL: http://svn.apache.org/viewvc?view=rev&rev=495000
Log:
Created new common interfaces to support the RequestResponseManager on both client and server
Added:
incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/AMQResponseCallback.java
incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/protocol/AMQProtocolWriter.java
Modified:
incubator/qpid/branches/qpid.0-9/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java
incubator/qpid/branches/qpid.0-9/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/RequestResponseManager.java
Modified: incubator/qpid/branches/qpid.0-9/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java?view=diff&rev=495000&r1=494999&r2=495000
==============================================================================
--- incubator/qpid/branches/qpid.0-9/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java (original)
+++ incubator/qpid/branches/qpid.0-9/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java Wed Jan 10 13:47:30 2007
@@ -27,8 +27,9 @@
import javax.security.sasl.SaslServer;
+import org.apache.qpid.protocol.AMQProtocolWriter;
-public interface AMQProtocolSession
+public interface AMQProtocolSession extends AMQProtocolWriter
{
/**
* Called when a protocol data block is received
@@ -37,11 +38,13 @@
*/
void dataBlockReceived(AMQDataBlock message) throws Exception;
- /**
- * Write a datablock, encoding where necessary (e.g. into a sequence of bytes)
- * @param frame the frame to be encoded and written
- */
- void writeFrame(AMQDataBlock frame);
+// This is now a part of AMQProtocolWriter (inherited) to provide uniformity across both
+// client and server.
+// /**
+// * Write a datablock, encoding where necessary (e.g. into a sequence of bytes)
+// * @param frame the frame to be encoded and written
+// */
+// void writeFrame(AMQDataBlock frame);
/**
* Get the context key associated with this session. Context key is described
Modified: incubator/qpid/branches/qpid.0-9/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java?view=diff&rev=495000&r1=494999&r2=495000
==============================================================================
--- incubator/qpid/branches/qpid.0-9/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java (original)
+++ incubator/qpid/branches/qpid.0-9/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java Wed Jan 10 13:47:30 2007
@@ -36,6 +36,7 @@
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.ProtocolInitiation;
import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.protocol.AMQProtocolWriter;
import org.apache.commons.lang.StringUtils;
import javax.jms.JMSException;
@@ -49,7 +50,7 @@
* The underlying protocol session is still available but clients should not
* use it to obtain session attributes.
*/
-public class AMQProtocolSession implements ProtocolVersionList
+public class AMQProtocolSession implements AMQProtocolWriter, ProtocolVersionList
{
protected static final int LAST_WRITE_FUTURE_JOIN_TIMEOUT = 1000 * 60 * 2;
Added: incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/AMQResponseCallback.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/AMQResponseCallback.java?view=auto&rev=495000
==============================================================================
--- incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/AMQResponseCallback.java (added)
+++ incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/AMQResponseCallback.java Wed Jan 10 13:47:30 2007
@@ -0,0 +1,32 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+public interface AMQResponseCallback
+{
+ /**
+ * Callback for response frames. An instance of this class must be
+ * passed to RequestResponseManager.sendRequest(). When a response
+ * is received, then this method will be invoked in the passed
+ * instance.
+ */
+ public void responseFrameReceived(AMQResponseBody responseBody);
+}
Modified: incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/RequestResponseManager.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/RequestResponseManager.java?view=diff&rev=495000&r1=494999&r2=495000
==============================================================================
--- incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/RequestResponseManager.java (original)
+++ incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/framing/RequestResponseManager.java Wed Jan 10 13:47:30 2007
@@ -20,17 +20,16 @@
*/
package org.apache.qpid.framing;
-import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.TreeMap;
import org.apache.qpid.AMQException;
-//import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.protocol.AMQProtocolWriter;
public class RequestResponseManager
{
private int channel;
-// AMQProtocolSession protocolSession;
+ AMQProtocolWriter protocolSession;
/**
* Determines the batch behaviour of the manager.
@@ -88,30 +87,29 @@
}
}
- private TreeMap<Long, Method> requestSentMap;
+ private TreeMap<Long, AMQResponseCallback> requestSentMap;
private TreeMap<Long, ResponseStatus> responseMap;
-// public RequestResponseManager(int channel, AMQProtocolSession protocolSession)
- public RequestResponseManager(int channel)
+ public RequestResponseManager(int channel, AMQProtocolWriter protocolSession)
{
this.channel = channel;
-// this.protocolSession = protocolSession;
+ this.protocolSession = protocolSession;
requestIdCount = 1L;
responseIdCount = 1L;
lastReceivedRequestId = 0L;
lastReceivedResponseId = 0L;
- requestSentMap = new TreeMap<Long, Method>();
+ requestSentMap = new TreeMap<Long, AMQResponseCallback>();
responseMap = new TreeMap<Long, ResponseStatus>();
}
// *** Functions to originate a request ***
- public long sendRequest(AMQMethodBody requestMethodBody, Method responseCallback)
+ public long sendRequest(AMQMethodBody requestMethodBody, AMQResponseCallback responseCallback)
{
long requestId = getRequestId(); // Get new request ID
AMQFrame requestFrame = AMQRequestBody.createAMQFrame(channel, requestId,
lastReceivedResponseId, requestMethodBody);
-// protocolSession.writeFrame(requestFrame);
+ protocolSession.writeFrame(requestFrame);
requestSentMap.put(requestId, responseCallback);
return requestId;
}
@@ -123,12 +121,11 @@
long requestIdStop = requestIdStart + responseBody.getBatchOffset();
for (long requestId = requestIdStart; requestId <= requestIdStop; requestId++)
{
- Method responseCallback = requestSentMap.get(requestId);
+ AMQResponseCallback responseCallback = requestSentMap.get(requestId);
if (responseCallback == null)
throw new AMQException("Failed to locate requestId " + requestId +
" in requestSentMap.");
- // TODO
- // responseCallback.invoke(?);
+ responseCallback.responseFrameReceived(responseBody);
requestSentMap.remove(requestId);
}
}
@@ -138,11 +135,13 @@
public void requestReceived(AMQRequestBody requestBody)
{
long requestId = requestBody.getRequestId();
- long responseMark = requestBody.getResponseMark(); // TODO - what do we do with this??
+ // TODO: responseMark is used in HA, but until then, ignore...
+ long responseMark = requestBody.getResponseMark();
lastReceivedRequestId = requestId;
responseMap.put(requestId, new ResponseStatus(requestId));
- // TODO: Initiate some action based on the MethodBody
+ // TODO: Initiate some action based on the MethodBody - like send to handlers,
+ // but how to do this in a way that will work for both client and server?
}
public void sendResponse(long requestId, AMQMethodBody responseMethodBody) throws AMQException
@@ -185,14 +184,6 @@
return responseIdCount++;
}
-/* private Method findRequest(long requestId)
- throws AMQException
- {
- RequestStatus requestStatus = requestMap.get(requestId);
- // TODO
- return null;
- }
-*/
private void doBatches()
{
switch (batchResponseMode)
@@ -210,6 +201,10 @@
}
}
break;
+
+ // TODO: Add additional batch mode handlers here...
+ // case DELAY_FIXED:
+ // case MANUAL:
}
}
@@ -219,6 +214,6 @@
long responseId = getResponseId(); // Get new request ID
AMQFrame responseFrame = AMQResponseBody.createAMQFrame(channel, responseId,
firstRequestId, numAdditionalRequests, responseMethodBody);
-// protocolSession.writeFrame(responseFrame);
+ protocolSession.writeFrame(responseFrame);
}
}
Added: incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/protocol/AMQProtocolWriter.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/protocol/AMQProtocolWriter.java?view=auto&rev=495000
==============================================================================
--- incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/protocol/AMQProtocolWriter.java (added)
+++ incubator/qpid/branches/qpid.0-9/java/common/src/main/java/org/apache/qpid/protocol/AMQProtocolWriter.java Wed Jan 10 13:47:30 2007
@@ -0,0 +1,32 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.protocol;
+
+import org.apache.qpid.framing.AMQDataBlock;
+
+public interface AMQProtocolWriter
+{
+ /**
+ * Write a datablock, encoding where necessary (e.g. into a sequence of bytes)
+ * @param frame the frame to be encoded and written
+ */
+ public void writeFrame(AMQDataBlock frame);
+}