PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist160410/src/edu/vub/at/actors/net/cmd/CMDTransmitATMessage.java

http://ambienttalk.googlecode.com/
Java | 74 lines | 23 code | 8 blank | 43 comment | 0 complexity | 97fb202fd8e710e4c246f4d11eabdcd8 MD5 | raw file
 1/**
 2 * AmbientTalk/2 Project
 3 * CMDTransmitATMessage.java created on 22-feb-2007 at 14:23:11
 4 * (c) Programming Technology Lab, 2006 - 2007
 5 * Authors: Tom Van Cutsem & Stijn Mostinckx
 6 * 
 7 * Permission is hereby granted, free of charge, to any person
 8 * obtaining a copy of this software and associated documentation
 9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28package edu.vub.at.actors.net.cmd;
29
30import edu.vub.at.actors.id.ActorID;
31import edu.vub.at.actors.natives.ELVirtualMachine;
32import edu.vub.at.actors.natives.Packet;
33import edu.vub.at.actors.net.comm.Address;
34import edu.vub.at.actors.net.comm.CommunicationBus;
35import edu.vub.at.actors.net.comm.NetworkException;
36
37
38/**
39 * A CMDTransmitATMessage message encapsulates an AmbientTalk message being sent
40 * from a sending actor to a recipient actor.
41 * 
42 * SENDER: a remote far reference
43 * RECEIVER: the VM hosting the object that the far reference denotes
44 * MODE: SYNCHRONOUS, UNICAST
45 * PROPERTIES:
46 *  - Packet representing serialized AT message,
47 *  - id of the actor that should unserialize and process the message
48 * REPLY: no other VM command, but should return synchronous acknowledgement
49 * 
50 * @author tvcutsem
51 */
52public class CMDTransmitATMessage extends VMCommand {
53
54	private static final long serialVersionUID = -1369124457059610846L;
55	
56	private final Packet serializedATMessage_;
57	private final ActorID destinationActorId_;
58	
59	public CMDTransmitATMessage(ActorID destinationActorId, Packet atMessage) {
60		super("transmitATMessage("+atMessage+")");
61		serializedATMessage_ = atMessage;
62		destinationActorId_ = destinationActorId;
63	}
64	
65	public void send(CommunicationBus dispatcher, Address recipientVM) throws NetworkException {
66		dispatcher.sendSynchronousUnicast(this, recipientVM);
67	}
68	
69	public void uponReceiptBy(ELVirtualMachine remoteHost, Address senderAddress) {
70		remoteHost.getActor(destinationActorId_).event_remoteAccept(senderAddress, serializedATMessage_);
71		// we do not need to send an explicit acknowledgement to the sender: if the transmission over
72		// its socket was successful, it knows that the message has at least arrived without failure.
73	}
74}