⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invokeserver.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: InvokeServer.java,v 1.7 2002/12/29 11:15:56 per_nyfelt Exp $

package org.ozoneDB.core;

import java.io.IOException;
import java.net.Socket;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.DxLib.net.*;
import org.ozoneDB.*;
import org.ozoneDB.core.DbRemote.*;
import org.ozoneDB.util.*;


/**
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 * @version $Revision: 1.7 $Date: 2002/12/29 11:15:56 $
 */
public class InvokeServer extends DxMultiServer {

    protected transient Env env;


    public InvokeServer( Env _env, int port ) throws IOException{
        super( port );
        env = _env;
    }


    public void startup() throws Exception {
        env.logWriter.newEntry( this, "startup...", LogWriter.INFO );
    }


    public void shutdown() throws Exception {
        env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO );
        close();
    }


    public void handleClientEvent(DxMultiServerClient client,Object event) {
//      env.logWriter.newEntry( this, "handleClientEvent()...", LogWriter.DEBUG3 );
        try {
            DbCommand cmd = (DbCommand)event;
            cmd.env = env;

            if (cmd instanceof DbOpen) {
                DbOpen command = (DbOpen)cmd;
                User user = env.userManager.userForName( command.userName() );

                if (user == null) {
                    client.send( new PermissionDeniedException( "No such user: " + command.userName() + "." ) );
                } else {
                    ((DbInvokeClient)client).user = user;
                    ((CommandThread)Thread.currentThread()).setOwner( user );
                    env.logWriter.newEntry( this, "user logged in: " + command.userName(), LogWriter.DEBUG );
                    client.send( null );
                }
            } else  if (cmd instanceof DbCloseConn) {
                removeClient( client );
            } else  if (cmd instanceof DbReloadClasses) {
                env.classManager.dropClasses();
                // AbstractObjectContainer.flushMethodCache();
                client.send( new Integer( 0 ) );
            } else {
            	/*
                User user = ((DbInvokeClient)client).user;
                env.transactionManager.handleCommand( cmd, user );
                */
                DbInvokeClient dbInvokeClient = (DbInvokeClient) client;

                cmd.setProxyObjectGate(dbInvokeClient.getProxyObjectGate());
                env.transactionManager.handleCommand(cmd,dbInvokeClient);

                if (cmd.shouldResultBeSentToClient()) {
                    client.send(cmd.result);
                }
            }
        } catch (Error e) {
            env.logWriter.newEntry( this, "handleClientEvent(): " + e, e, LogWriter.WARN );
            throw e;
        } catch (Exception e) {
            // exceptions that are catched here are related to any network problem
            // since user and internal exceptions are catched in Transactions or
            // the TransactionManager

            // TODO: should this shutdown the connection?
            env.logWriter.newEntry( this, "handleClientEvent(): " + e, e, LogWriter.WARN );
        }
    }


    public void handleClientException( DxMultiServerClient client, Exception e ) {
        env.logWriter.newEntry( this, "handleClientException(): " + e, e, LogWriter.WARN );
        removeClient( client );
    }


    public DxMultiServerClient newClient( Socket sock ) {
        try {
            DbInvokeClient dc = new DbInvokeClient( sock, this );
            env.logWriter.newEntry( this, "connection established...", LogWriter.DEBUG );
            return dc;
        }
        catch (Exception e) {
            env.logWriter.newEntry( this, "newClient(): ", e, LogWriter.WARN );
            return null;
        }
    }


    public void removeClient( DxMultiServerClient client ) {
        env.logWriter.newEntry( this, "close connection...", LogWriter.DEBUG3 );
        env.logWriter.newEntry( this, "close pending transaction...", LogWriter.DEBUG3 );
        env.transactionManager.handleCommand(new DbCloseConn(),(User) null);

        super.removeClient( client );
        String userName = ((DbInvokeClient)client).user != null ? ((DbInvokeClient)client).user.name() : "none";
        env.logWriter.newEntry( this, "connection closed (user: " + userName + ")", LogWriter.DEBUG );
    }


    public Thread newThread( Runnable run ) {
        Thread thread;
        if (run == acceptor) {
            thread = new Thread( threadGroup(), run );
            thread.setPriority( Env.ACCEPT_THREAD_PRIORITY );
        } else {
            thread = new CommandThread( threadGroup(), run );
            thread.setPriority( Env.TRANSACTION_THREAD_PRIORITY );
        }
        thread.setDaemon( true );
        return thread;
    }

    /**
		Starts filtering references to database objects ({@link OzoneProxy}s) which
		are exported to clients at all client connections.
		Every reference which is exported will be notified to the given GarbageCollector.
		Additionally, references which are known to be used by clients are notified to the
		given GarbageCollector within this call.
    */
    public void startFilterDatabaseObjectReferencesExports(GarbageCollector garbageCollector) {
    	synchronized (this) {
    		DxIterator i = iterator();

    		while (i.next()!=null) {
                ((DbInvokeClient) i.object()).getProxyObjectGate().startFilterDatabaseObjectReferencesExports(garbageCollector);
    		}
    	}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -