Search in sources :

Example 1 with EngineFactory

use of com.ramussoft.server.EngineFactory in project ramus by Vitaliy-Yakovchuk.

the class InternetServer method run.

private void run(String[] args) throws IOException {
    new File(tmpPath).mkdirs();
    engineFactory = new EngineFactory() {
    };
    final ServerSocket ss = new ServerSocket();
    ss.bind(new InetSocketAddress("0.0.0.0", Metadata.INTERNET_PORT));
    userFactory = new UserFactoryImpl(engineFactory.getTemplate());
    serverAccessRules = new ServerAccessRules(engineFactory.getEngine(), userFactory) {

        @Override
        protected String getLogin() {
            return logins.get(Thread.currentThread());
        }
    };
    Thread acceptionThread = new Thread(new Runnable() {

        @Override
        public void run() {
            System.out.println("Ramus Interner Server ready");
            while (true) {
                try {
                    final Thread thread;
                    final Socket socket = ss.accept();
                    CheckableUserFactory userFactoryClient = new CheckableUserFactory(userFactory);
                    IntegrityAccessorSuit suit = new IntegrityAccessorSuit();
                    suit.addAccessRules(serverAccessRules);
                    suit.addAccessRules(((IEngineImpl) getEngine().getDeligate()).getAccessor());
                    final ClientServiceImpl service = new ClientServiceImpl(InternetServer.this, userFactory, userFactoryClient);
                    SuperInvoker invoker = new SuperInvoker(new Object[] { service, suit, userFactoryClient, service }, new Class[] { ClientService.class, AccessRules.class, UserFactory.class, UserProvider.class });
                    final TcpServerConnection connection = new TcpServerConnection(socket, new String[] { ClientService.class.getName(), AccessRules.class.getName(), UserFactory.class.getName(), UserProvider.class.getName() }, invoker.createProxy()) {

                        public void close() throws IOException {
                            synchronized (servicesLock) {
                                services.remove(service);
                            }
                            service.close();
                            super.close();
                        }
                    };
                    synchronized (servicesLock) {
                        services.add(service);
                    }
                    thread = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            connection.run();
                        }
                    }, "server-client");
                    service.setConnection(connection);
                    thread.start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }, "inet-server-main");
    acceptionThread.start();
}
Also used : EngineFactory(com.ramussoft.server.EngineFactory) IntegrityAccessorSuit(com.ramussoft.core.impl.IntegrityAccessorSuit) ClientService(com.ramussoft.net.common.internet.ClientService) InetSocketAddress(java.net.InetSocketAddress) UserFactory(com.ramussoft.net.common.UserFactory) CheckableUserFactory(com.ramussoft.server.CheckableUserFactory) ServerSocket(java.net.ServerSocket) SuperInvoker(com.ramussoft.net.common.SuperInvoker) IOException(java.io.IOException) TcpServerConnection(com.ramussoft.server.TcpServerConnection) UserFactoryImpl(com.ramussoft.server.UserFactoryImpl) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) UserProvider(com.ramussoft.net.common.UserProvider) ServerAccessRules(com.ramussoft.server.ServerAccessRules) ServerAccessRules(com.ramussoft.server.ServerAccessRules) AccessRules(com.ramussoft.common.AccessRules) CheckableUserFactory(com.ramussoft.server.CheckableUserFactory) RedoObject(com.ramussoft.net.common.internet.RedoObject) UndoObject(com.ramussoft.net.common.internet.UndoObject) File(java.io.File) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Aggregations

AccessRules (com.ramussoft.common.AccessRules)1 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)1 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)1 IntegrityAccessorSuit (com.ramussoft.core.impl.IntegrityAccessorSuit)1 SuperInvoker (com.ramussoft.net.common.SuperInvoker)1 UserFactory (com.ramussoft.net.common.UserFactory)1 UserProvider (com.ramussoft.net.common.UserProvider)1 ClientService (com.ramussoft.net.common.internet.ClientService)1 RedoObject (com.ramussoft.net.common.internet.RedoObject)1 UndoObject (com.ramussoft.net.common.internet.UndoObject)1 CheckableUserFactory (com.ramussoft.server.CheckableUserFactory)1 EngineFactory (com.ramussoft.server.EngineFactory)1 ServerAccessRules (com.ramussoft.server.ServerAccessRules)1 TcpServerConnection (com.ramussoft.server.TcpServerConnection)1 UserFactoryImpl (com.ramussoft.server.UserFactoryImpl)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1