1 /***
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id: ServerFacade.java,v 1.5 2005/09/07 23:34:26 mat007 Exp $
29 */
30
31 package jtge.sample.chat.server.core;
32
33 import jtge.engine.data.Context;
34 import jtge.engine.data.IContext;
35 import jtge.engine.handler.Executor;
36 import jtge.engine.handler.IConsumer;
37 import jtge.engine.io.IInputOutputImpFactory;
38 import jtge.engine.io.IStatusObserver;
39 import jtge.engine.io.ObjectInputOutputFactory;
40 import jtge.engine.net.IServerView;
41 import jtge.engine.net.Server;
42 import jtge.engine.security.ILoginView;
43 import jtge.engine.security.LoginObserver;
44 import jtge.engine.security.UserChannelManager;
45 import jtge.sample.chat.common.core.IMessageView;
46
47 /***
48 * Provides a server facade.
49 *
50 * @author Mathieu Champlon
51 * @version $Revision: 1.5 $ $Date: 2005/09/07 23:34:26 $
52 */
53 public class ServerFacade implements IController
54 {
55 private final IContext context;
56 private final UserChannelManager manager;
57 private final LoginObserver observer;
58 private final Server server;
59
60 /***
61 * Create a server.
62 */
63 public ServerFacade()
64 {
65 context = new Context();
66 final IConsumer consumer = new Executor( context );
67 final IInputOutputImpFactory factory = new ObjectInputOutputFactory();
68 manager = new UserChannelManager();
69 server = new Server( consumer, factory, manager );
70 observer = new LoginObserver( server );
71 manager.register( observer );
72 server.register( manager );
73 context.put( IConsumer.class, server );
74 }
75
76 /***
77 * {@inheritDoc}
78 */
79 public final void register( final IServerView view )
80 {
81 server.register( view );
82 }
83
84 /***
85 * {@inheritDoc}
86 */
87 public final void register( final IStatusObserver view )
88 {
89 server.register( view );
90 }
91
92 /***
93 * {@inheritDoc}
94 */
95 public final void register( final ILoginView view )
96 {
97 observer.register( view );
98 }
99
100 /***
101 * {@inheritDoc}
102 */
103 public final void register( final IMessageView view )
104 {
105 context.put( IMessageView.class, view );
106 }
107
108 /***
109 * {@inheritDoc}
110 */
111 public final void open( final int port )
112 {
113 server.open( port );
114 }
115
116 /***
117 * {@inheritDoc}
118 */
119 public final void close()
120 {
121 server.close();
122 }
123 }