PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://ambienttalk.googlecode.com/
Java | 79 lines | 23 code | 8 blank | 48 comment | 0 complexity | 05af4a423f32e32d4f0cbdaf4912b493 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.ELVirtualMachine;
  31. import edu.vub.at.actors.natives.Packet;
  32. import edu.vub.at.actors.net.comm.Address;
  33. import edu.vub.at.actors.net.comm.CommunicationBus;
  34. import edu.vub.at.actors.net.comm.NetworkException;
  35. /**
  36. * A CMDTransmitATMessage message encapsulates an AmbientTalk message being sent
  37. * from a sending actor to a recipient actor.
  38. *
  39. * SENDER: a remote far reference
  40. * RECEIVER: the VM hosting the object that the far reference denotes
  41. * MODE: SYNCHRONOUS, UNICAST
  42. * PROPERTIES:
  43. * - Packet representing serialized AT message,
  44. * - id of the actor that should unserialize and process the message
  45. * REPLY: no other VM command, but should return synchronous acknowledgement
  46. *
  47. * @author tvcutsem
  48. */
  49. public class CMDTransmitATMessage extends VMCommand {
  50. private static final long serialVersionUID = -1369124457059610846L;
  51. private final Packet serializedATMessage_;
  52. private final ActorID destinationActorId_;
  53. public CMDTransmitATMessage(ActorID destinationActorId, Packet atMessage) {
  54. super("transmitATMessage("+atMessage+")");
  55. serializedATMessage_ = atMessage;
  56. destinationActorId_ = destinationActorId;
  57. }
  58. public void send(CommunicationBus dispatcher, Address recipientVM) throws NetworkException {
  59. dispatcher.sendSynchronousUnicast(this, recipientVM);
  60. }
  61. public void uponReceiptBy(ELVirtualMachine remoteHost, Address senderAddress) {
  62. remoteHost.getActor(destinationActorId_).event_remoteAccept(senderAddress, serializedATMessage_);
  63. // we do not need to send an explicit acknowledgement to the sender: if the transmission over
  64. // its socket was successful, it knows that the message has at least arrived without failure.
  65. // TODO: this may not be the case... JDK 1.5 documentation for flush() says:
  66. // If the intended destination of this stream is an abstraction provided by the underlying operating
  67. // system, for example a file, then flushing the stream guarantees only that bytes previously written
  68. // to the stream are passed to the operating system for writing; it does not guarantee that they are
  69. // actually written to a physical device such as a disk drive.
  70. }
  71. }