001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Core License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: InvokeServer.java,v 1.3 2002/06/25 11:34:38 mediumnet Exp $
008:
009: package org.ozoneDB.core;
010:
011: import java.io.IOException;
012: import java.net.Socket;
013: import org.ozoneDB.DxLib.*;
014: import org.ozoneDB.DxLib.net.*;
015: import org.ozoneDB.*;
016: import org.ozoneDB.core.DbRemote.*;
017: import org.ozoneDB.util.*;
018:
019: /**
020: * @author <a href="http://www.softwarebuero.de/">SMB</a>
021: * @version $Revision: 1.3 $Date: 2002/06/25 11:34:38 $
022: */
023: public class InvokeServer extends DxMultiServer {
024:
025: protected transient Env env;
026:
027: public InvokeServer(Env _env, int port) throws IOException {
028: super (port);
029: env = _env;
030: }
031:
032: public void startup() throws Exception {
033: env.logWriter.newEntry(this , "startup...", LogWriter.INFO);
034: }
035:
036: public void shutdown() throws Exception {
037: env.logWriter.newEntry(this , "shutdown...", LogWriter.INFO);
038: close();
039: }
040:
041: public void handleClientEvent(DxMultiServerClient client,
042: Object event) {
043: // env.logWriter.newEntry( this, "handleClientEvent()...", LogWriter.DEBUG3 );
044: try {
045: DbCommand cmd = (DbCommand) event;
046: cmd.env = env;
047:
048: if (cmd instanceof DbOpen) {
049: DbOpen command = (DbOpen) cmd;
050: User user = env.userManager.userForName(command
051: .userName());
052:
053: if (user == null) {
054: client
055: .send(new PermissionDeniedExc(
056: "No such user: "
057: + command.userName() + "."));
058: } else {
059: ((DbInvokeClient) client).user = user;
060: ((CommandThread) Thread.currentThread())
061: .setOwner(user);
062: env.logWriter.newEntry(this , "user logged in: "
063: + command.userName(), LogWriter.INFO);
064: client.send(null);
065: }
066: } else if (cmd instanceof DbCloseConn) {
067: removeClient(client);
068: } else if (cmd instanceof DbReloadClasses) {
069: env.classManager.dropClasses();
070: // AbstractObjectContainer.flushMethodCache();
071: client.send(new Integer(0));
072: } else {
073: /*
074: User user = ((DbInvokeClient)client).user;
075: env.transactionManager.handleCommand( cmd, user );
076: */
077: DbInvokeClient dbInvokeClient = (DbInvokeClient) client;
078:
079: cmd.setProxyObjectGate(dbInvokeClient
080: .getProxyObjectGate());
081: env.transactionManager.handleCommand(cmd,
082: dbInvokeClient);
083:
084: if (cmd.shouldResultBeSentToClient()) {
085: client.send(cmd.result);
086: }
087: }
088: } catch (Exception e) {
089: // exceptions that are catched here are related to any network problem
090: // since user and internal exceptions are catched in Transactions or
091: // the TransactionManager
092:
093: // TODO: should this shutdown the connection?
094: env.logWriter.newEntry(this , "handleClientEvent(): " + e,
095: e, LogWriter.WARN);
096: }
097: }
098:
099: public void handleClientException(DxMultiServerClient client,
100: Exception e) {
101: env.logWriter.newEntry(this , "handleClientException(): " + e,
102: e, LogWriter.WARN);
103: removeClient(client);
104: }
105:
106: public DxMultiServerClient newClient(Socket sock) {
107: try {
108: DbInvokeClient dc = new DbInvokeClient(sock, this );
109: env.logWriter.newEntry(this , "connection established...",
110: LogWriter.INFO);
111: return dc;
112: } catch (Exception e) {
113: env.logWriter.newEntry(this , "newClient(): ", e,
114: LogWriter.WARN);
115: return null;
116: }
117: }
118:
119: public void removeClient(DxMultiServerClient client) {
120: env.logWriter.newEntry(this , "close connection...",
121: LogWriter.DEBUG3);
122: env.logWriter.newEntry(this , "close pending transaction...",
123: LogWriter.DEBUG3);
124: env.transactionManager.handleCommand(new DbCloseConn(),
125: (User) null);
126:
127: super .removeClient(client);
128: String userName = ((DbInvokeClient) client).user != null ? ((DbInvokeClient) client).user
129: .name()
130: : "none";
131: env.logWriter.newEntry(this , "connection closed (user: "
132: + userName + ")", LogWriter.INFO);
133: }
134:
135: public Thread newThread(Runnable run) {
136: Thread thread;
137: if (run == acceptor) {
138: thread = new Thread(threadGroup(), run);
139: thread.setPriority(Env.ACCEPT_THREAD_PRIORITY);
140: } else {
141: thread = new CommandThread(threadGroup(), run);
142: thread.setPriority(Env.TRANSACTION_THREAD_PRIORITY);
143: }
144: thread.setDaemon(true);
145: return thread;
146: }
147:
148: /**
149: Starts filtering references to database objects ({@link OzoneProxy}s) which
150: are exported to clients at all client connections.
151: Every reference which is exported will be notified to the given GarbageCollector.
152: Additionally, references which are known to be used by clients are notified to the
153: given GarbageCollector within this call.
154: */
155: public void startFilterDatabaseObjectReferencesExports(
156: GarbageCollector garbageCollector) {
157: synchronized (this ) {
158: DxIterator i = iterator();
159:
160: while (i.next() != null) {
161: ((DbInvokeClient) i.object()).getProxyObjectGate()
162: .startFilterDatabaseObjectReferencesExports(
163: garbageCollector);
164: }
165: }
166: }
167: }
|