Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.remoting.samples.chat.server;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  
 
 import  org.jboss.logging.Logger;

Title: Chat4

Description:

Copyright: Copyright (c) 2003

Company:

Author(s):
not attributable
Version:
1.0
 
 
 public class ChatServer_Impl implements ServerInvocationHandler
 {
    protected static final Logger log = Logger.getLogger(ChatServer_Impl.class);
    
    private Map callbackThreadMap = new HashMap();
    private ShutDownGate shutDownGate;
    private boolean shuttingDown = false;
 
    
    public ChatServer_Impl(ExtendedChatInfo eciShutDownGate sdg)
    {
        = eci;
        = sdg;
    }
 
    
    public Object invoke(InvocationRequest invocationthrows Throwable
    {
       if (!(invocation.getParameter() instanceof RemoteInvocation))
          throw new Exception("invalid request format: expecting NameBasedInvocation");
          
       RemoteInvocation request = (RemoteInvocationinvocation.getParameter();
       String methodName = request.getMethodName();
       Object[] args = request.getParameters();
 
       if (methodName.equals("getBackChat"))
          return getBackChat(args);
       
       if (methodName.equals("getChatInfo"))
          return getChatInfo(args);
       
       if (methodName.equals("leave"))
       {
          leave(args);
          return null;
       }
       
       if (methodName.equals("send"))
       {
          send(args);
          return null;
       }
 
       .error("unrecognized method name: " + methodName);
       throw new Exception("unrecognized method name: " + methodName);
    }
    
    
    protected ArrayList getBackChat(Object[] argsthrows ShuttingDownException
    {
       .enter();
       ReadWriteArrayList messages = .getMessages();
 
       if (messages == null)
       {
          ..println("messages == null");
          messages = new ReadWriteArrayList();
       }
 
       ArrayList returnMessages = messages.toArrayList();
       .leave();
       return returnMessages;
    }
 
 
    protected ChatInfo getChatInfo(Object[] argsthrows ShuttingDownException
   {
      .check();
      ChatInfo chatInfo = .getChatInfo();
      chatInfo.set_size(.getMessages().size());
      return chatInfo;
   }
   
   protected void leave(Object[] argsthrows ShuttingDownException
   {
      ChatMember member = (ChatMemberargs[0];
      .enter();
      ..println("ChatServer.leave(): member leaving: " + member.get_name());
      .removeMember(member);
      .leave();
   }
   
   protected void send(Object[] argsthrows ShuttingDownException
   {
      ChatMessage mesg = (ChatMessageargs[0];
      .enter();
      messages.add(mesg);
      .leave();
   }   
   
   public void setMBeanServer(MBeanServer server)
   {
   }
   public void setInvoker(ServerInvoker invoker)
   {
   }
   public void addListener(InvokerCallbackHandler callbackHandler)
   {
      CallbackThread t = new CallbackThread(callbackHandler.getMessages());
      .put(callbackHandlert);
      t.start();
   }
   public void removeListener(InvokerCallbackHandler callbackHandler)
   {
      CallbackThread t = (CallbackThread.remove(callbackHandler);
      
      if (t != null)
         t.setMemberLeaving();
   }
New to GrepCode? Check out our FAQ X