1 package org.sapia.ubik.rmi.server.command; 2 3 import org.sapia.ubik.net.ServerAddress; 4 import org.sapia.ubik.rmi.server.Log; 5 import org.sapia.ubik.rmi.server.VmId; 6 7 8 19 public class CommandProcessor { 20 private ExecQueue _in; 21 22 25 public CommandProcessor(int maxThreads) throws IllegalStateException { 26 try { 27 _in = new InQueue(maxThreads); 28 } catch (Exception e) { 29 e.printStackTrace(); 30 throw new IllegalStateException (e.getMessage()); 31 } 32 } 33 34 40 public Object processSyncCommand(Command cmd) { 41 try { 42 return cmd.execute(); 43 } catch (Throwable t) { 44 return t; 45 } 46 } 47 48 55 public void processAsyncCommand(String cmdId, VmId caller, 56 ServerAddress from, Command cmd) { 57 _in.add(new AsyncCommand(cmdId, caller, from, cmd)); 58 } 59 60 67 public void setResponseSender(ResponseSender sender) { 68 OutQueue.setResponseSender(sender); 69 } 70 71 82 public void shutdown(long timeout) throws InterruptedException { 83 Log.warning(getClass(), "Shutting down incoming command queue"); 84 _in.shutdown(timeout); 85 Log.warning(getClass(), "Shutting down outgoing response queue"); 86 OutQueue.shutdownAll(timeout); 87 } 88 } 89 | Popular Tags |