View Javadoc

1   /*
2      Copyright 2008 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.rpc.events;
17  
18  import static fulmine.util.Utils.COMMA_SPACE;
19  import fulmine.event.IEventManager;
20  import fulmine.event.system.AbstractSystemEvent;
21  
22  /**
23   * Raised by the sending context to send the RPC to the remote context.
24   * 
25   * @see RpcInvokeEvent
26   * @author Ramon Servadei
27   */
28  public final class SendRpcEvent extends AbstractSystemEvent
29  {
30  
31      /** The raw bytes to send to the remote context */
32      private final byte[] rpcData;
33  
34      /** The identity of the remote context to send the RPC to */
35      private final String remoteContextIdentity;
36  
37      /**
38       * Construct the event to encapsulate the RPC to send
39       * 
40       * @param context
41       *            the local context
42       * @param remoteContextIdentity
43       *            the remote context that the RPC is targetted at
44       * @param rpcData
45       *            the RPC data in its <code>byte[]</code> form
46       */
47      public SendRpcEvent(IEventManager context, String remoteContextIdentity,
48          byte[] rpcData)
49      {
50          super(context);
51          this.remoteContextIdentity = remoteContextIdentity;
52          this.rpcData = rpcData;
53      }
54  
55      /**
56       * Get the identity of the remote context to send the RPC to
57       * 
58       * @return the identity of the remote context to send the RPC to
59       */
60      public String getRemoteContextIdentity()
61      {
62          return this.remoteContextIdentity;
63      }
64  
65      /**
66       * Get the raw bytes to send to the remote context
67       * 
68       * @return the raw bytes to send to the remote context
69       */
70      public byte[] getRpcData()
71      {
72          return this.rpcData;
73      }
74  
75      @Override
76      protected String getAdditionalToString()
77      {
78          return "remoteContext=" + getRemoteContextIdentity() + COMMA_SPACE
79              + "rpcData=" + new String(getRpcData());
80      }
81  
82  }