1 9 package org.ozoneDB.core; 10 11 import java.io.IOException ; 12 import java.net.Socket ; 13 import org.ozoneDB.DxLib.*; 14 import org.ozoneDB.DxLib.net.*; 15 import org.ozoneDB.*; 16 import org.ozoneDB.core.DbRemote.*; 17 import org.ozoneDB.util.*; 18 19 20 24 public class InvokeServer extends DxMultiServer { 25 26 protected transient Env env; 27 28 29 public InvokeServer( Env _env, int port ) throws IOException { 30 super( port ); 31 env = _env; 32 } 33 34 35 public void startup() throws Exception { 36 env.logWriter.newEntry( this, "startup...", LogWriter.INFO ); 37 } 38 39 40 public void shutdown() throws Exception { 41 env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO ); 42 close(); 43 } 44 45 46 public void handleClientEvent(DxMultiServerClient client,Object event) { 47 try { 49 DbCommand cmd = (DbCommand)event; 50 cmd.env = env; 51 52 if (cmd instanceof DbOpen) { 53 DbOpen command = (DbOpen)cmd; 54 User user = env.userManager.userForName( command.userName() ); 55 56 if (user == null) { 57 client.send( new PermissionDeniedException( "No such user: " + command.userName() + "." ) ); 58 } else { 59 ((DbInvokeClient)client).user = user; 60 ((CommandThread)Thread.currentThread()).setOwner( user ); 61 env.logWriter.newEntry( this, "user logged in: " + command.userName(), LogWriter.DEBUG ); 62 client.send( null ); 63 } 64 } else if (cmd instanceof DbCloseConn) { 65 removeClient( client ); 66 } else if (cmd instanceof DbReloadClasses) { 67 env.classManager.dropClasses(); 68 client.send( new Integer ( 0 ) ); 70 } else { 71 75 DbInvokeClient dbInvokeClient = (DbInvokeClient) client; 76 77 cmd.setProxyObjectGate(dbInvokeClient.getProxyObjectGate()); 78 env.transactionManager.handleCommand(cmd,dbInvokeClient); 79 80 if (cmd.shouldResultBeSentToClient()) { 81 client.send(cmd.result); 82 } 83 } 84 } catch (Error e) { 85 env.logWriter.newEntry( this, "handleClientEvent(): " + e, e, LogWriter.WARN ); 86 throw e; 87 } catch (Exception e) { 88 92 env.logWriter.newEntry( this, "handleClientEvent(): " + e, e, LogWriter.WARN ); 94 } 95 } 96 97 98 public void handleClientException( DxMultiServerClient client, Exception e ) { 99 env.logWriter.newEntry( this, "handleClientException(): " + e, e, LogWriter.WARN ); 100 removeClient( client ); 101 } 102 103 104 public DxMultiServerClient newClient( Socket sock ) { 105 try { 106 DbInvokeClient dc = new DbInvokeClient( sock, this ); 107 env.logWriter.newEntry( this, "connection established...", LogWriter.DEBUG ); 108 return dc; 109 } 110 catch (Exception e) { 111 env.logWriter.newEntry( this, "newClient(): ", e, LogWriter.WARN ); 112 return null; 113 } 114 } 115 116 117 public void removeClient( DxMultiServerClient client ) { 118 env.logWriter.newEntry( this, "close connection...", LogWriter.DEBUG3 ); 119 env.logWriter.newEntry( this, "close pending transaction...", LogWriter.DEBUG3 ); 120 env.transactionManager.handleCommand(new DbCloseConn(),(User) null); 121 122 super.removeClient( client ); 123 String userName = ((DbInvokeClient)client).user != null ? ((DbInvokeClient)client).user.name() : "none"; 124 env.logWriter.newEntry( this, "connection closed (user: " + userName + ")", LogWriter.DEBUG ); 125 } 126 127 128 public Thread newThread( Runnable run ) { 129 Thread thread; 130 if (run == acceptor) { 131 thread = new Thread ( threadGroup(), run ); 132 thread.setPriority( Env.ACCEPT_THREAD_PRIORITY ); 133 } else { 134 thread = new CommandThread( threadGroup(), run ); 135 thread.setPriority( Env.TRANSACTION_THREAD_PRIORITY ); 136 } 137 thread.setDaemon( true ); 138 return thread; 139 } 140 141 148 public void startFilterDatabaseObjectReferencesExports(GarbageCollector garbageCollector) { 149 synchronized (this) { 150 DxIterator i = iterator(); 151 152 while (i.next()!=null) { 153 ((DbInvokeClient) i.object()).getProxyObjectGate().startFilterDatabaseObjectReferencesExports(garbageCollector); 154 } 155 } 156 } 157 } 158 | Popular Tags |