View Javadoc

1   /*
2      Copyright 2007 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.distribution.connection;
17  
18  import fulmine.ILifeCycle;
19  import fulmine.context.IFrameworkContext;
20  import fulmine.distribution.events.ConnectionAvailableEvent;
21  import fulmine.distribution.events.ConnectionDestroyedEvent;
22  import fulmine.distribution.events.MessageEvent;
23  import fulmine.event.IEventSource;
24  
25  /**
26   * Encapsulates the I/O connection between a local {@link IFrameworkContext} and
27   * a remote context. When the I/O connection is created and is available, a
28   * {@link ConnectionAvailableEvent} is raised. When the I/O connection is closed
29   * or suffers a disconnect, a {@link ConnectionDestroyedEvent} is raised.
30   * <p>
31   * Data is sent to the remote context using the {@link #send(byte[])} method.
32   * When data is received from the remote context a {@link MessageEvent} is
33   * raised.
34   * 
35   * @author Ramon Servadei
36   * 
37   */
38  public interface IConnection extends IEventSource, ILifeCycle,
39      IConnectionParameters
40  {
41      /**
42       * Send the data to the remote {@link IFrameworkContext}. This may not be a
43       * synchronous action; the implementation may queue the data.
44       * 
45       * @param data
46       *            the data to send
47       */
48      void send(byte[] data);
49  
50      /**
51       * Indicates if this connection was initiated by the local context. This can
52       * only occur via a call to
53       * {@link IConnectionBroker#connect(IConnectionParameters)}.
54       * 
55       * @return <code>true</code> if the local context initiated this connection,
56       *         <code>false</code> if the connection was created by accepting the
57       *         connection request from a remote context.
58       */
59      boolean isOutbound();
60  }