use of com.ramussoft.server.UserFactoryImpl in project ramus by Vitaliy-Yakovchuk.
the class EngineConnection method init.
public void init(String[] args) throws Exception {
try {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
java.sql.Connection jdbcConnection = null;
Properties ps = EngineFactory.getPropeties();
if (ps != null) {
try {
Class.forName(ps.getProperty("driver"));
jdbcConnection = DriverManager.getConnection(ps.getProperty("url"), ps.getProperty("user"), ps.getProperty("password"));
} catch (Exception e) {
e.printStackTrace();
}
}
if (jdbcConnection == null)
jdbcConnection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1/ramus_public", "postgres", "postgres");
template = new JDBCTemplate(jdbcConnection);
userFactory = new UserFactoryImpl(template);
JDBCTemplate template = new JDBCTemplate(jdbcConnection);
String password = template.queryForObjects("SELECT \"password\" FROM users WHERE \"login\"=?", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int index) throws SQLException {
return rs.getString(1);
}
}, new Object[] { "admin" }, true).toString().trim();
connection = new TcpClientConnection("127.0.0.1", Metadata.TCP_PORT) {
@Override
protected void objectReaded(Object object) {
if (tcpClientEngine != null)
tcpClientEngine.call((EvenstHolder) object);
}
};
connection.start();
connection.invoke("login", new Object[] { "admin", password });
tcpClientEngine = new TcpClientEngine((EngineInvocker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EngineInvocker.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return connection.invoke(method.getName(), args);
}
}), connection);
List<Class> interfaces = new ArrayList<Class>();
interfaces.add(Engine.class);
interfaces.add(Journaled.class);
List<PluginProvider> suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
initAdditionalPluginSuits(suits);
PluginFactory factory = createPluginFactory(suits);
for (Plugin plugin : factory.getPlugins()) if (plugin.getFunctionalInterface() != null)
interfaces.add(plugin.getFunctionalInterface());
final Engine engine1 = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), tcpClientEngine);
// new CachedEngine(engine1);
final Engine cachedEngine = engine1;
final Hashtable<Method, Object> hashtable = new Hashtable<Method, Object>();
for (Method m : Engine.class.getMethods()) {
hashtable.put(m, cachedEngine);
}
for (Method m : Cached.class.getMethods()) {
hashtable.put(m, cachedEngine);
}
interfaces.add(Cached.class);
Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object o = hashtable.get(method);
if (o == null)
return tcpClientEngine.invoke(proxy, method, args);
return method.invoke(o, args);
}
});
tcpClientEngine.setEngine(engine);
for (Plugin plugin : factory.getPlugins()) plugin.init(engine, rules);
rules = (AccessRules) createDeligate(AccessRules.class);
this.engine = engine;
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ramussoft.server.UserFactoryImpl 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();
}
use of com.ramussoft.server.UserFactoryImpl 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();
}
Aggregations