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();
}
Aggregations