1 24 25 package org.objectweb.tribe.gms; 26 27 import org.objectweb.tribe.channel.ReceiveBuffer; 28 import org.objectweb.tribe.common.log.Trace; 29 import org.objectweb.tribe.exceptions.EmptyBufferException; 30 import org.objectweb.tribe.gms.protocol.GroupMembershipMessage; 31 import org.objectweb.tribe.messages.ChannelMessage; 32 33 42 public class GroupMembershipListenerThread extends Thread 43 { 44 private GroupMembershipService listener; 45 private ReceiveBuffer receiveBuffer; private boolean isKilled = false; 48 private Trace logger; 49 50 53 public GroupMembershipListenerThread(GroupMembershipService gms) 54 { 55 super("GroupMembershipListenerThread"); 56 this.listener = gms; 57 logger = GroupMembershipService.getLogger(); 58 } 59 60 63 public void kill() 64 { 65 isKilled = true; 66 receiveBuffer.addMessage(null); 68 } 69 70 73 public void run() 74 { 75 if (logger.isDebugEnabled()) 76 logger.debug("GroupMembershipListenerThread started"); 77 receiveBuffer = listener.getReceiveBuffer(); 78 while (!isKilled) 79 { 80 try 81 { 82 ChannelMessage msg = receiveBuffer.getMessage(); 83 if (msg instanceof GroupMembershipMessage) 84 { 85 if (logger.isDebugEnabled()) 86 logger.debug("Delivering GMS message: " + msg); 87 GroupMembershipMessage gmsMsg = (GroupMembershipMessage) msg; 88 gmsMsg.deliver(listener); 89 } 90 else 91 logger 92 .debug("Unexpected message type in GroupMembershipListenerThread:" 93 + msg); 94 } 95 catch (EmptyBufferException e) 96 { 97 logger.error("Error while getting message for GMS service", e); 98 } 99 } 100 } 101 } | Popular Tags |