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.events;
17  
18  import fulmine.context.IFrameworkContext;
19  import fulmine.distribution.connection.IConnection;
20  import fulmine.event.IEventManager;
21  import fulmine.event.system.AbstractSystemEvent;
22  
23  /**
24   * A system event raised by an {@link IConnection} implementation and includes
25   * the connection to the remote {@link IFrameworkContext} that is available for
26   * use.
27   * 
28   * @author Ramon Servadei
29   */
30  public final class ConnectionAvailableEvent extends AbstractSystemEvent
31  {
32      /**
33       * The available connection to a remote {@link IFrameworkContext}
34       */
35      private final IConnection connection;
36  
37      /**
38       * Standard constructor to encapsulate the available connection to a remote
39       * {@link IFrameworkContext}
40       * 
41       * @param context
42       *            the context for event operations
43       * @param connection
44       *            the available connection to a remote context
45       */
46      public ConnectionAvailableEvent(IEventManager context,
47          IConnection connection)
48      {
49          super(context);
50          this.connection = connection;
51      }
52  
53      /**
54       * Get the connection to the remote {@link IFrameworkContext}
55       * 
56       * @param <T>
57       *            an {@link IConnection} type
58       * @return the connection to the remote context
59       */
60      @SuppressWarnings("unchecked")
61      public <T extends IConnection> T getConnection()
62      {
63          return (T) connection;
64      }
65  
66      @Override
67      public String toDetailedString()
68      {
69          return toString();
70      }
71  
72      @Override
73      public String toIdentityString()
74      {
75          return toString();
76      }
77  
78      @Override
79      protected String getAdditionalToString()
80      {
81          return "connection=" + getConnection();
82      }
83  }