/**
 * 
 */
package com.trendrr.oss.messaging.channel;


import com.trendrr.oss.DynMap;
import com.trendrr.oss.concurrent.SafeBox;


/**
 * @author Dustin Norlander
 * @created May 16, 2012
 * 
 */
public class ChannelRequest {
	String endpoint = "";
	Object[] inputs;
	
	SafeBox<ChannelResponse> response = new SafeBox<ChannelResponse>();
	
	public ChannelRequest(String endpoint, Object ...inputs) {
		this.endpoint = endpoint;
		this.inputs = inputs;
	}

	public String getEndpoint() {
		return endpoint;
	}

	public void setEndpoint(String endpoint) {
		this.endpoint = endpoint;
	}

	public Object[] getInputs() {
		return inputs;
	}
	
	public void setResponse(ChannelResponse response) {
		try {
			this.response.set(response);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public ChannelResponse awaitResponse() throws InterruptedException {
		return response.getAndClear();
		
	}
}

@@ -50,16 +50,56 @@
 nnel;%0A%0A%0A
+import java.util.concurrent.Semaphore;%0A%0A
 import c
@@ -306,23 +306,57 @@
 ts;%0A%09%0A%09S
-afeBox%3C
+emaphore lock = new Semaphore(1, true);%0A%09
 ChannelR
@@ -362,17 +362,16 @@
 Response
-%3E
  respons
@@ -379,37 +379,11 @@
  = n
-ew SafeBox%3CChannelResponse%3E()
+ull
 ;%0A%09%0A
@@ -494,16 +494,98 @@
 inputs;%0A
+%09%09try %7B%0A%09%09%09lock.acquire(1);%0A%09%09%7D catch (Exception x) %7B%0A%09%09%09x.printStackTrace();%0A%09%09%7D%0A
 %09%7D%0A%0A%09pub
@@ -844,21 +844,19 @@
 onse
-.set(
+ = 
 response
 );%0A%09
@@ -851,16 +851,35 @@
 response
+;%0A%09%09%09lock.release(1
 );%0A%09%09%7D c
@@ -884,27 +884,16 @@
  catch (
-Interrupted
 Exceptio
@@ -1021,19 +1021,8 @@
 ows 
-Interrupted
 Exce
@@ -1029,16 +1029,35 @@
 ption %7B%0A
+%09%09lock.acquire(1);%0A
 %09%09return
@@ -1069,22 +1069,8 @@
 onse
-.getAndClear()
 ;%0A%09%09
@@ -1074,9 +1074,8 @@
 %0A%09%09%0A%09%7D%0A%7D
-%0A

use semaphore for the channel request. slightly faster then the safebox implementation