Search in sources :

Example 1 with ServerAccessRules

use of com.ramussoft.server.ServerAccessRules 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)

Example 2 with ServerAccessRules

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

the class TcpServer method start.

@SuppressWarnings("unused")
public void start() throws IOException {
    File file = new File(tmpPath);
    if (!file.mkdirs()) {
        for (File f : file.listFiles()) f.delete();
    }
    Properties ps = EngineFactory.getPropeties();
    if ((ps == null) && (!com.ramussoft.common.Metadata.CORPORATE))
        ps = new Properties();
    String host = ps.getProperty("hostname");
    if (host != null) {
        System.setProperty("java.rmi.server.hostname", host);
    }
    Journal.checkThreads = false;
    final ServerSocket ss = createServerSocket();
    userFactory = new UserFactoryImpl(engineFactory.getTemplate());
    serverAccessRules = new ServerAccessRules(engineFactory.getEngine(), userFactory) {

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

        @Override
        public void run() {
            System.out.println("Ramus Server ready");
            while (true) {
                try {
                    final Socket socket = ss.accept();
                    final Thread thread;
                    final RamusService service = createRamusService();
                    Object proxy = service.createProxy();
                    final TcpServerConnection connection = new TcpServerConnection(socket, service.getClasses(), proxy) {

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

                        @Override
                        public void run() {
                            connection.run();
                        }
                    };
                    service.setConnection(connection);
                    startAcceptionThread(executorService, runnable);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }, "server-main");
    acceptionThread.start();
}
Also used : ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) Properties(java.util.Properties) TcpServerConnection(com.ramussoft.server.TcpServerConnection) UserFactoryImpl(com.ramussoft.server.UserFactoryImpl) ServerAccessRules(com.ramussoft.server.ServerAccessRules) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 3 with ServerAccessRules

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

the class EngineConnection method getAccessRules.

public AccessRules getAccessRules(final User finalUser) {
    if (finalUser == null)
        return rules;
    IntegrityAccessorSuit suit = new IntegrityAccessorSuit();
    suit.addAccessRules(rules);
    suit.addAccessRules(new ServerAccessRules(engine, userFactory) {

        @Override
        public User getUser() {
            return finalUser;
        }
    });
    return suit;
}
Also used : IntegrityAccessorSuit(com.ramussoft.core.impl.IntegrityAccessorSuit) User(com.ramussoft.net.common.User) ServerAccessRules(com.ramussoft.server.ServerAccessRules)

Aggregations

ServerAccessRules (com.ramussoft.server.ServerAccessRules)3 IntegrityAccessorSuit (com.ramussoft.core.impl.IntegrityAccessorSuit)2 TcpServerConnection (com.ramussoft.server.TcpServerConnection)2 UserFactoryImpl (com.ramussoft.server.UserFactoryImpl)2 File (java.io.File)2 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 AccessRules (com.ramussoft.common.AccessRules)1 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)1 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)1 SuperInvoker (com.ramussoft.net.common.SuperInvoker)1 User (com.ramussoft.net.common.User)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