📄 adminport.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-2000 by SMB GmbH. All rights reserved.//// $Id: AdminPort.java,v 1.23 2000/10/28 16:55:16 daniela Exp $package org.ozoneDB.core;import java.io.IOException;import java.net.Socket;import java.lang.reflect.*;import org.ozoneDB.tools.*;import org.ozoneDB.util.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.DxLib.net.*;public class AdminPort extends DxMultiServer { protected transient Env env; protected DxClient commandPort; protected DxClient messagePort; public AdminPort( Env _env, int port ) throws IOException{ super( port ); env = _env; accept(); } 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 synchronized void handleClientEvent( DxMultiServerClient client, Object event ) { try { if (client == commandPort) { AdminCommand command = (AdminCommand)event; env.logWriter.newEntry( this, "commandPort: " + command.toString(), LogWriter.INFO ); switch (command.command) { // new user case AdminCommand.NU: { String userName = (String)command.args[0]; int id = ((Integer)command.args[1]).intValue(); if (id < 100) { throw new UserManagerExc( "IDs <100 are reserved by the system." ); } env.userManager.newUser( userName, id ); commandPort.send( Boolean.TRUE ); break; } // new group case AdminCommand.NG: { String groupName = (String)command.args[0]; int id = ((Integer)command.args[1]).intValue(); if (id < 100) { throw new UserManagerExc( "IDs <100 are reserved by the system." ); } env.userManager.newGroup( groupName, id ); commandPort.send( Boolean.TRUE ); break; } // user to group case AdminCommand.U2G: { String userName = (String)command.args[0]; String groupName = (String)command.args[1]; env.userManager.addUserToGroup( userName, groupName ); commandPort.send( Boolean.TRUE ); break; } // show all users case AdminCommand.AU: { Object result = env.userManager.allUsers(); commandPort.send( result ); break; } // show all groups case AdminCommand.AG: { Object result = env.userManager.allGroups(); commandPort.send( result ); break; } // case AdminCommand.RUG: { String userName = (String)command.args[0]; String groupName = (String)command.args[1]; env.userManager.removeUserFromGroup( userName, groupName ); commandPort.send( Boolean.TRUE ); break; } // case AdminCommand.RU: { String userName = (String)command.args[0]; env.userManager.removeUser( userName ); commandPort.send( Boolean.TRUE ); break; } // case AdminCommand.RG: { String groupName = (String)command.args[0]; env.userManager.removeGroup( groupName ); commandPort.send( Boolean.TRUE ); break; } // case AdminCommand.GfN: { String groupName = (String)command.args[0]; commandPort.send( env.userManager.groupForName( groupName ) ); break; } // case AdminCommand.UfN: { String userName = (String)command.args[0]; commandPort.send( env.userManager.userForName( userName ) ); break; } // cluster(space) size case AdminCommand.CS: { env.logWriter.newEntry( this, "currently not supported", LogWriter.WARN ); // int clsize = ((Integer)command.args[1]).intValue(); // int cssize = ((Integer)command.args[0]).intValue(); // env.store.setSizes (cssize, clsize); break; } // shutdown case AdminCommand.SHUTDOWN: { env.logWriter.newEntry( this, "Shutdown.", LogWriter.INFO ); removeClient( client ); commandPort = null; env.shutdown(); break; } // close case AdminCommand.CLOSE: { env.logWriter.newEntry( this, "Admin logged out.", LogWriter.INFO ); removeClient( client ); commandPort = null; break; } default: { throw new UserManagerExc( "Function not implemented yet." ); } } } else { if (client == messagePort) { AdminCommand command = (AdminCommand)event; env.logWriter.newEntry( this, "messagePort: " + command.toString(), LogWriter.INFO ); switch (command.command) { // close case AdminCommand.CLOSE: { removeClient( client ); messagePort = null; break; } // shutdown // case AdminCommand.SHUTDOWN : { // close(); // env.shutdown(); // break; // } } } } } catch (Exception e) { env.logWriter.newEntry( this, "", e, LogWriter.WARN ); try { commandPort.send( e ); } catch (Exception ee) { env.logWriter.newEntry( this, "Unable to send exception.", LogWriter.WARN ); } } } public void handleClientException( DxMultiServerClient client, Exception e ) { env.logWriter.newEntry( this, "handleClientException(): " + e, e, LogWriter.WARN ); } public synchronized void sendMessage( String object, String msg ) { try { messagePort.send( new AdminMessage( object, msg ) ); } catch (Exception e) { env.logWriter.newEntry( this, "", e, LogWriter.WARN ); } } /** */ public synchronized DxMultiServerClient newClient( Socket sock ) { try { DxMultiServerClient client = new DxMultiServerClient( sock, this ); String s = (String)client.receive(); if (s.equals( "Command" )) { commandPort = client; env.logWriter.newEntry( this, "Admin logged in.", LogWriter.INFO ); } else { if (s.equals( "Message" )) { messagePort = client; } } return client; } catch (Exception e) { env.logWriter.newEntry( this, "", e, LogWriter.WARN ); } return null; } /** */ public Thread newThread( Runnable run ) { Thread t = new Thread( threadGroup(), run ); t.setPriority( Env.ACCEPT_THREAD_PRIORITY ); return t; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -