PageRenderTime 28ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/branches/rfid/src/edu/vub/at/actors/net/cmd/CMDTransmitATMessage.java

http://ambienttalk.googlecode.com/
Java | 77 lines | 26 code | 8 blank | 43 comment | 0 complexity | 1a821a8290bd1d3402750e41ced5f796 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1
  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. */
  28. package edu.vub.at.actors.net.cmd;
  29. import edu.vub.at.actors.id.ActorID;
  30. import edu.vub.at.actors.natives.ELActor;
  31. import edu.vub.at.actors.natives.ELVirtualMachine;
  32. import edu.vub.at.actors.natives.Packet;
  33. import edu.vub.at.actors.net.comm.Address;
  34. import edu.vub.at.actors.net.comm.CommunicationBus;
  35. import edu.vub.at.actors.net.comm.NetworkException;
  36. /**
  37. * A CMDTransmitATMessage message encapsulates an AmbientTalk message being sent
  38. * from a sending actor to a recipient actor.
  39. *
  40. * SENDER: a remote far reference
  41. * RECEIVER: the VM hosting the object that the far reference denotes
  42. * MODE: SYNCHRONOUS, UNICAST
  43. * PROPERTIES:
  44. * - Packet representing serialized AT message,
  45. * - id of the actor that should unserialize and process the message
  46. * REPLY: no other VM command, but should return synchronous acknowledgement
  47. *
  48. * @author tvcutsem
  49. */
  50. public class CMDTransmitATMessage extends VMCommand {
  51. private static final long serialVersionUID = -1369124457059610846L;
  52. private final Packet serializedATMessage_;
  53. private final ActorID destinationActorId_;
  54. public CMDTransmitATMessage(ActorID destinationActorId, Packet atMessage) {
  55. super("transmitATMessage("+atMessage+")");
  56. serializedATMessage_ = atMessage;
  57. destinationActorId_ = destinationActorId;
  58. }
  59. public void send(CommunicationBus dispatcher, Address recipientVM) throws NetworkException {
  60. dispatcher.sendSynchronousUnicast(this, recipientVM);
  61. }
  62. public void uponReceiptBy(ELVirtualMachine remoteHost, Address senderAddress) {
  63. ELActor a = remoteHost.getActor(destinationActorId_);
  64. System.err.println("Actor to process msg is: " + a.toString());
  65. a.event_remoteAccept(senderAddress, serializedATMessage_);
  66. // we do not need to send an explicit acknowledgement to the sender: if the transmission over
  67. // its socket was successful, it knows that the message has at least arrived without failure.
  68. }
  69. }