當前位置: 首頁>>代碼示例>>Java>>正文


Java FunctionResponseMessage類代碼示例

本文整理匯總了Java中com.uniquid.messages.FunctionResponseMessage的典型用法代碼示例。如果您正苦於以下問題:Java FunctionResponseMessage類的具體用法?Java FunctionResponseMessage怎麽用?Java FunctionResponseMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FunctionResponseMessage類屬於com.uniquid.messages包,在下文中一共展示了FunctionResponseMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSendOutputMessage

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Test
public void testSendOutputMessage() {
	String sender = "sender";
	int method = 5;
	String params = "params";
	
	FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser(sender);
	providerRequest.setFunction(method);
	providerRequest.setParameters(params);
	
	String broker = "tcp://appliance4.uniquid.co:1883"; 
	String destination = "test";
	int timeout = 10;
	
	final MQTTUserClient mqttUserClient = new MQTTUserClient(broker, destination, timeout, sender);
	Assert.assertNotNull(mqttUserClient);
	
	new Thread(new Runnable() {
		
		@Override
		public void run() {				
			startMqttServerMock();				
		}
	}).start();

	try {
		FunctionResponseMessage providerResponse = (FunctionResponseMessage) mqttUserClient.execute(providerRequest);
		Assert.assertNotNull(providerResponse);
		
		Assert.assertEquals(providerResponse.getId(), providerRequest.getId());
	} catch (UserClientException e) {
		Assert.fail();
	}				

}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:37,代碼來源:MQTTUserClientTest.java

示例2: startMqttServerMock

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
private void startMqttServerMock() {
	
	String broker = "tcp://appliance4.uniquid.co:1883";
	String topic = "test";
	Topic[] topics = {new Topic(topic, QoS.AT_LEAST_ONCE)};
	BlockingConnection connection = null;
	
	try{
		MQTT mqtt = new MQTT();
		mqtt.setHost(broker);
		connection = mqtt.blockingConnection();
		connection.connect();
		connection.subscribe(topics);
		// blocks!!!
		Message message = connection.receive();
		
		byte[] payload = message.getPayload();

		message.ack();
		
		Assert.assertNotNull(message);

		FunctionRequestMessage rpcProviderRequest = (FunctionRequestMessage) new JSONMessageSerializer().deserialize(payload);
		Assert.assertNotNull(rpcProviderRequest);
		
		FunctionResponseMessage rpcProviderResponse = new FunctionResponseMessage();
		rpcProviderResponse.setProvider("test");
		rpcProviderResponse.setError(0);
		rpcProviderResponse.setResult("result");
		rpcProviderResponse.setId(rpcProviderRequest.getId());
		
		connection.publish(rpcProviderRequest.getUser(), new JSONMessageSerializer().serialize(rpcProviderResponse), QoS.AT_LEAST_ONCE, false);
		
		connection.disconnect();			
		
	} catch (Throwable t) {
		Assert.fail();
	}
}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:40,代碼來源:MQTTUserClientTest.java

示例3: startMqttServerMockException

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
private void startMqttServerMockException() {
	
	String broker = "tcp://appliance4.uniquid.co:1883";
	String topic = "test";
	Topic[] topics = {new Topic(topic, QoS.AT_LEAST_ONCE)};
	BlockingConnection connection = null;
	
	try{
		MQTT mqtt = new MQTT();
		mqtt.setHost(broker);
		connection = mqtt.blockingConnection();
		connection.connect();
		connection.subscribe(topics);
		// blocks!!!
		Message message = connection.receive();
		
		byte[] payload = message.getPayload();

		message.ack();
		
		Assert.assertNotNull(message);
					
		FunctionRequestMessage functionRequestMessage = (FunctionRequestMessage) new JSONMessageSerializer().deserialize(payload);
		Assert.assertNotNull(functionRequestMessage);

		FunctionResponseMessage functionResponseMessage = new FunctionResponseMessage();
		functionResponseMessage.setProvider("sender");
		functionResponseMessage.setResult("result");
		functionResponseMessage.setError(0);
		
		connection.disconnect();			
		
	} catch (Throwable t) {
		Assert.fail();
	}
}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:37,代碼來源:MQTTUserClientTest.java

示例4: getOutputMessage

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public FunctionResponseMessage getOutputMessage() {
	return providerResponse;
}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:5,代碼來源:TCPEndPoint.java

示例5: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload)
		throws FunctionException, IOException {
	
	Tank tank = Tank.getInstance();
	
	String params = inputMessage.getParameters();
	String result = "";
	if (params.startsWith("open")) {
		
		tank.openInput();
		
		result = "\nOpening in faucet\n-- Level " + tank.getLevel() + " in faucet = " +  booleanToInt(tank.isInputOpen()) + " out faucet = " + booleanToInt(tank.isOutputOpen()) + "\n";
		
	} else if (params.startsWith("close")) {
		
		tank.closeInput();
		
		result = "\nClosing in faucet\n-- Level " + tank.getLevel() + " in faucet = " +  booleanToInt(tank.isInputOpen()) + " out faucet = " + booleanToInt(tank.isOutputOpen()) + "\n";
		
	}
	
	outputMessage.setResult(result);
	
}
 
開發者ID:uniquid,項目名稱:tank-java,代碼行數:26,代碼來源:InputFaucetFunction.java

示例6: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload)
		throws FunctionException, IOException {
	
	Tank tank = Tank.getInstance();
	
	String params = inputMessage.getParameters();
	String result = "";
	if (params.startsWith("open")) {
		
		tank.open();
		
		result = "\nOpening Machine\n-- Level " + tank.getLevel() + " in faucet = " + booleanToInt(tank.isInputOpen()) + " out faucet = " +  booleanToInt(tank.isOutputOpen()) + "\n";
		
	} else if (params.startsWith("close")) {
		
		tank.close();
		
		result = "\nClosing Machine\n-- Level " + tank.getLevel() + " in faucet = " + booleanToInt(tank.isInputOpen()) + " out faucet = " +  booleanToInt(tank.isOutputOpen()) + "\n";
		
	}
	
	outputMessage.setResult(result);
	
}
 
開發者ID:uniquid,項目名稱:tank-java,代碼行數:26,代碼來源:TankFunction.java

示例7: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload)
		throws FunctionException, IOException {
	
	Tank tank = Tank.getInstance();
	
	String params = inputMessage.getParameters();
	String result = "";
	if (params.startsWith("open")) {
		
		tank.openOutput();
		
		result = "\nOpening out faucet\n-- Level " + tank.getLevel() + " in faucet = " + booleanToInt(tank.isInputOpen()) + " out faucet = " + booleanToInt(tank.isOutputOpen()) + "\n";
		
	} else if (params.startsWith("close")) {
		
		tank.closeOutput();
		
		result = "\nClosing out faucet\n-- Level " + tank.getLevel() + " in faucet = " + booleanToInt(tank.isInputOpen()) + " out faucet = " + booleanToInt(tank.isOutputOpen()) + "\n";
		
	}
	
	outputMessage.setResult(result);
	
}
 
開發者ID:uniquid,項目名稱:tank-java,代碼行數:26,代碼來源:OutputFaucetFunction.java

示例8: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public abstract void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload)
		throws FunctionException, IOException;
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:4,代碼來源:GenericFunction.java

示例9: MQTTEndPoint

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
/**
 * Creates a new instance from the byte array message and broker
 * @param mqttMessageRequest the message received
 * @param broker the broker to use
 * @throws ConnectorException in case a problem occurs.
 */
MQTTEndPoint(final byte[] mqttMessageRequest, final String broker) throws ConnectorException {
	
	this.broker = broker;

	try {
		
		UniquidMessage messageReceived = messageSerializer.deserialize(mqttMessageRequest);
		
		if (MessageType.FUNCTION_REQUEST.equals(messageReceived.getMessageType())) {
			
			// Retrieve message
			providerRequest = (FunctionRequestMessage) messageReceived;
					
			providerResponse = new FunctionResponseMessage();
			providerResponse.setId(providerRequest.getId());
			
		} else {
		
			throw new Exception("Received an invalid message type " + messageReceived.getMessageType());
		
		}
	
	} catch (Exception ex) {
		
		throw new ConnectorException("Exception during creation of endpoint", ex);
	
	}
}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:35,代碼來源:MQTTEndPoint.java

示例10: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Override
public void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload)
		throws FunctionException, IOException {
	
	outputMessage.setResult("UID_echo: " + inputMessage.getParameters());
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:8,代碼來源:EchoFunction.java

示例11: TCPEndPoint

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
/**
 * Creates a new instance from the byte array message and broker
 * @param mqttMessageRequest the message received
 * @param broker the broker to use
 * @throws ConnectorException in case a problem occurs.
 */
TCPEndPoint(Socket socket) throws ConnectorException {
	
	this.socket = socket;

	try {
		
		DataInputStream inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream()));

		byte[] length = new byte[PREFIX_LEN];
		int size = inputStream.read(length, 0, PREFIX_LEN);

		// TODO WE SHOULD PUT AN UPPER LIMIT HERE TO AVOID LEAKS/MALICIOUS REQUESTS...
		
		ByteBuffer buffer = ByteBuffer.wrap(length);
		int num = buffer.getInt();

		int len = 0;
		byte[] msg = new byte[num];

		int r = inputStream.read(msg, 0, msg.length);
		
		UniquidMessage messageReceived = messageSerializer.deserialize(msg);
		
		if (MessageType.FUNCTION_REQUEST.equals(messageReceived.getMessageType())) {
			
			// Retrieve message
			providerRequest = (FunctionRequestMessage) messageReceived;
					
			providerResponse = new FunctionResponseMessage();
			providerResponse.setId(providerRequest.getId());
			
		} else {
		
			throw new Exception("Received an invalid message type " + messageReceived.getMessageType());
		
		}
	
	} catch (Exception ex) {
		
		throw new ConnectorException("Exception during creation of endpoint", ex);
	
	}
}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:50,代碼來源:TCPEndPoint.java

示例12: run

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
public void run() {

		while (!Thread.currentThread().isInterrupted()) {

			try {

				EndPoint endPoint = connector.accept();

				UniquidMessage inputMessage = endPoint.getInputMessage();

				FunctionResponseMessage outputMessage = (FunctionResponseMessage) endPoint.getOutputMessage();

				if (MessageType.FUNCTION_REQUEST.equals(inputMessage.getMessageType())) {

					LOGGER.info("Received input message {}", inputMessage.getMessageType());

				} else {

					LOGGER.info("Unknown message type {} received", inputMessage.getMessageType());

					throw new Exception("Unknown message type");

				}

				LOGGER.info("Forwarding request via TCP");
				FunctionResponseMessage response = (FunctionResponseMessage) userClient.execute(inputMessage);

				LOGGER.info("Received response!");
				outputMessage.setError(response.getError());
				outputMessage.setProvider(response.getProvider());
				outputMessage.setResult(response.getResult());

				LOGGER.info("Flushing response via MQTT");
				
				endPoint.flush();

			} catch (Throwable t) {

				LOGGER.error("Throwable catched", t);
				
			}

		}

	}
 
開發者ID:uniquid,項目名稱:uniquid-utils,代碼行數:46,代碼來源:MQTTProxySocket.java

示例13: performProviderRequest

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
/**
 * Perform the execution of a {@link Function} related to the {@link ProviderRequest} received.
 * 
 * @param providerRequest the {@link ProviderRequest} received from the User
 * @param providerResponse the {@link ProviderResponse} the response to provide to the User
 * 
 * @throws Exception in case a problem occurs.
 */
protected final void performProviderRequest(final FunctionRequestMessage providerRequest, final FunctionResponseMessage providerResponse, final byte[] payload) throws Exception {

	Function function = getFunction(providerRequest);

	try {

		if (function != null) {

			try {

				function.service(providerRequest, providerResponse, payload);
				providerResponse.setError(FunctionResponseMessage.RESULT_OK);

			} catch (Exception ex) {

				LOGGER.error("Error while executing function", ex);
				providerResponse.setError(FunctionResponseMessage.RESULT_ERROR);

				providerResponse.setResult("Error while executing function: " + ex.getMessage());
			}

		} else {

			providerResponse.setError(FunctionResponseMessage.RESULT_FUNCTION_NOT_AVAILABLE);
			
			providerResponse.setResult("Function not available");

		}

	} finally {

		// Populate all missing parameters...
		String sender = providerRequest.getUser();

		ProviderRegister providerRegister = registerFactory.getProviderRegister();

		ProviderChannel providerChannel = providerRegister.getChannelByUserAddress(sender);
		
		providerResponse.setProvider(providerChannel.getProviderAddress());

	}

}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:52,代碼來源:Core.java

示例14: service

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
/**
 * Request to execute the function
 * 
 * @param inputMessage message coming from user
 * @param outputMessage message coming from provider
 * @param payload payload from contract
 * @throws FunctionException in case a problem occurs during executing the function
 * @throws IOException
 */
public void service(FunctionRequestMessage inputMessage, FunctionResponseMessage outputMessage, byte[] payload) throws FunctionException, IOException;
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:11,代碼來源:Function.java

示例15: testService

import com.uniquid.messages.FunctionResponseMessage; //導入依賴的package包/類
@Test
public void testService() throws Exception {
	
	ContractFunction contractFunction = new ContractFunction();
	
	Assert.assertNotNull(contractFunction);
	
	FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("sender");
	providerRequest.setFunction(30);
	providerRequest.setParameters("{ }");

	FunctionResponseMessage providerResponse = new FunctionResponseMessage();
	
	try {

		contractFunction.service(providerRequest, providerResponse, null);
		
	} catch (FunctionException ex) {
		
		Assert.assertEquals("Problem with input JSON", ex.getMessage());
		
	}
	
	FunctionRequestMessage providerRequest2 = new FunctionRequestMessage();
	providerRequest2.setUser("sender");
	providerRequest2.setFunction(30);
	providerRequest2.setParameters("{ \"tx\":\"1234\", \"paths\": [\"1234\"] }");
	
	FunctionResponseMessage providerResponse2 = new FunctionResponseMessage();
	
	contractFunction.init(new FunctionConfig() {
		
		@Override
		public FunctionContext getFunctionContext() {
			ApplicationContext appContext = new ApplicationContext();
			appContext.setAttribute(Core.NODE_ATTRIBUTE, new DummyNode());
			
			return appContext;
		}
	});

	
	contractFunction.service(providerRequest2, providerResponse2, null);
	
	Assert.assertTrue(providerResponse2.getResult().startsWith("0"));
	
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:50,代碼來源:ContractFunctionTest.java


注:本文中的com.uniquid.messages.FunctionResponseMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。