Permalink
Browse files

removed MessageListenerAdapter and MembershipListenerAdapter (never u…

…sed, can be written in app code)
  • Loading branch information...
Bela Ban
Bela Ban committed Apr 11, 2011
1 parent cd817a8 commit 7eb7ad62705768741bd6f69372dd42ebb8b16b68
View
@@ -38,6 +38,10 @@ API changes in 3.0.0
- RpcDispatcher: merged Marshaller and Marshaller2 into Marshaller interface
+- Removed partial state transfer (nobody ever used it !)
+
+
+
@@ -5,7 +5,6 @@
/**
* Allows a listener to be notified when group membership changes.
- * These callbacks are used in {@link org.jgroups.blocks.PullPushAdapter}.
* <p>
* The MembershipListener interface is similar to the {@link MessageListener}
* interface: every time a new view, a suspicion message, or a
@@ -1,92 +0,0 @@
-package org.jgroups.blocks;
-
-import org.jgroups.Address;
-import org.jgroups.MembershipListener;
-import org.jgroups.View;
-import org.jgroups.ExtendedMembershipListener;
-
-import java.util.HashSet;
-
-/**
- * This class provides multiplexing possibilities for {@link MembershipListener}
- * instances. Usually, we have more than one instance willing to listen to
- * membership messages. {@link PullPushAdapter} allows only one instance of
- * {@link MembershipListener} to be registered for message notification. With
- * help of this class you can overcome this limitation.
- *
- * @author Roman Rokytskyy (rrokytskyy@acm.org)
- */
-
-public class MembershipListenerAdapter implements MembershipListener {
-
- protected final HashSet membershipListeners = new HashSet();
- protected MembershipListener[] membershipListenersCache =
- new MembershipListener[0];
-
- /**
- * Notify membership listeners to temporarily stop sending messages into
- * a channel. This method in turn calls same method of all registered
- * membership listener.
- */
- public void block() {
- for(int i = 0; i < membershipListenersCache.length; i++)
- membershipListenersCache[i].block();
- }
-
- public void unblock() {
- for(int i = 0; i < membershipListenersCache.length; i++) {
- if(membershipListenersCache[i] instanceof ExtendedMembershipListener)
- ((ExtendedMembershipListener)membershipListenersCache[i]).unblock();
- }
- }
-
-
- /**
- * Notify membership listener that some node was suspected. This method
- * in turn passes suspected member address to all registered membership
- * listeners.
- */
- public void suspect(Address suspected_mbr) {
- for(int i = 0; i < membershipListenersCache.length; i++)
- membershipListenersCache[i].suspect(suspected_mbr);
- }
-
- /**
- * Notify membership listener that new view was accepted. This method in
- * turn passes new view to all registered membership listeners.
- */
- public void viewAccepted(View new_view) {
- for(int i = 0; i < membershipListenersCache.length; i++)
- membershipListenersCache[i].viewAccepted(new_view);
- }
-
- /**
- * Add membership listener to this adapter. This method registers
- * <code>listener</code> to be notified when membership event is generated.
- *
- * @param listener instance of {@link MembershipListener} that should be
- * added to this adapter.
- */
- public synchronized void addMembershipListener(MembershipListener listener) {
- if (membershipListeners.add(listener))
- membershipListenersCache =
- (MembershipListener[])membershipListeners.toArray(
- new MembershipListener[membershipListeners.size()]);
- }
-
- /**
- * Remove membership listener from this adapter. This method deregisters
- * <code>listener</code> from notification when membership event is generated.
- *
- * @param listener instance of {@link MembershipListener} that should be
- * removed from this adapter.
- */
- public synchronized void removeMembershipListener(MembershipListener listener) {
- if (membershipListeners.remove(listener))
- membershipListenersCache =
- (MembershipListener[])membershipListeners.toArray(
- new MembershipListener[membershipListeners.size()]);
-
- }
-
-}
@@ -1,170 +0,0 @@
-package org.jgroups.blocks;
-
-import org.jgroups.Message;
-import org.jgroups.MessageListener;
-import org.jgroups.ExtendedMessageListener;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashSet;
-
-/**
- * This class provides multiplexing possibilities for {@link MessageListener}
- * instances. Usually, we have more than one instance willing to listen to
- * incoming messages, but only one that can produce state for group.
- * {@link PullPushAdapter} allows only one instance of {@link MessageListener}
- * to be registered for message notification. With help of this class you
- * can overcome this limitation.
- *
- * @author Roman Rokytskyy (rrokytskyy@acm.org)
- */
-public class MessageListenerAdapter implements ExtendedMessageListener {
-
- protected MessageListener stateListener;
-
- protected final HashSet messageListeners = new HashSet();
-
- // we need this cache, because every call to messageListeners.iterator()
- // would generate few new objects, but iteration over the cache would not.
- protected MessageListener[] messageListenersCache = new MessageListener[0];
-
- /**
- * Create default instance of this class. Newly created instance will have
- * no message or state listeners. You have to use
- * {@link #addMessageListener(MessageListener)} or
- * {@link #removeMessageListener(MessageListener)} to add or remove message
- * listeners, and {@link #setStateListener(MessageListener)} to set listener
- * that will participate in state transfer.
- */
- public MessageListenerAdapter() {
- this(null);
- }
-
- /**
- * Create instance of this class. <code>mainListener</code> is a main
- * listener instance that received message notifications and can get and
- * set group state.
- *
- * @param mainListener instance of {@link MessageListener} that will
- * provide state messages.
- */
- public MessageListenerAdapter(MessageListener mainListener) {
- if (mainListener != null) {
- stateListener = mainListener;
- addMessageListener(mainListener);
- }
- }
-
- /**
- * Get state from state listener if present.
- *
- * @return current state of the group state or <code>null</code> if no state
- * listeners were registered.
- */
- public byte[] getState() {
- if (stateListener != null)
- return stateListener.getState();
- else
- return null;
- }
-
-
- public byte[] getState(String state_id) {
- if(stateListener == null)
- return null;
- if(stateListener instanceof ExtendedMessageListener) {
- return ((ExtendedMessageListener)stateListener).getState(state_id);
- }
- else {
- return stateListener.getState();
- }
- }
-
- public void getState(OutputStream ostream) {
- if (stateListener instanceof ExtendedMessageListener) {
- ((ExtendedMessageListener) stateListener).getState(ostream);
- }
- }
-
- public void getState(String state_id, OutputStream ostream) {
- if (stateListener instanceof ExtendedMessageListener && state_id!=null) {
- ((ExtendedMessageListener) stateListener).getState(state_id,ostream);
- }
- }
-
- /**
- * Receive message from group. This method will send this message to each
- * message listener that was registered in this adapter.
- *
- * @param msg message to distribute within message listeners.
- */
- public void receive(Message msg) {
- for (int i = 0; i < messageListenersCache.length; i++)
- messageListenersCache[i].receive(msg);
- }
-
- /**
- * Set state of ths group. This method will delegate call to state listener
- * if it was previously registered.
- */
- public void setState(byte[] state) {
- if (stateListener != null)
- stateListener.setState(state);
- }
-
- public void setState(String state_id, byte[] state) {
- if(stateListener != null) {
- if(stateListener instanceof ExtendedMessageListener) {
- ((ExtendedMessageListener)stateListener).setState(state_id, state);
- }
- else {
- stateListener.setState(state);
- }
- }
- }
-
-
- public void setState(InputStream istream) {
- if (stateListener instanceof ExtendedMessageListener) {
- ((ExtendedMessageListener) stateListener).setState(istream);
- }
- }
-
- public void setState(String state_id, InputStream istream) {
- if (stateListener instanceof ExtendedMessageListener && state_id != null) {
- ((ExtendedMessageListener) stateListener).setState(state_id,istream);
- }
- }
-
- /**
- * Add message listener to this adapter. This method registers
- * <code>listener</code> for message notification.
- * <p>
- * Note, state notification will not be used.
- */
- public final synchronized void addMessageListener(MessageListener listener) {
- if (messageListeners.add(listener))
- messageListenersCache =
- (MessageListener[])messageListeners.toArray(
- new MessageListener[messageListeners.size()]);
- }
-
- /**
- * Remove message listener from this adapter. This method deregisters
- * <code>listener</code> from message notification.
- */
- public synchronized void removeMessageListener(MessageListener listener) {
- if (messageListeners.remove(listener))
- messageListenersCache =
- (MessageListener[])messageListeners.toArray(
- new MessageListener[messageListeners.size()]);
- }
-
- /**
- * Register <code>listener</code> for state notification events. There can
- * be only one state listener per adapter.
- */
- public void setStateListener(MessageListener listener) {
- stateListener = listener;
- }
-}
@@ -428,7 +428,7 @@ private Address getNode(K key) {
}
- public static class ConsistentHashFunction<K> extends MembershipListenerAdapter implements HashFunction<K> {
+ public static class ConsistentHashFunction<K> implements MembershipListener, HashFunction<K> {
private SortedMap<Short,Address> nodes=new TreeMap<Short,Address>();
private final static int HASH_SPACE=2000; // must be > max number of nodes in a cluster
@@ -471,6 +471,12 @@ public void viewAccepted(View new_view) {
}
}
+ public void suspect(Address suspected_mbr) {
+ }
+
+ public void block() {
+ }
+
private static Address findFirst(Map<Short,Address> map, int index) {
Address retval;
@@ -485,70 +491,7 @@ private static Address findFirst(Map<Short,Address> map, int index) {
}
- /**
- * Uses arrays to store hash values of addresses, plus addresses.
- */
- public static class ArrayBasedConsistentHashFunction<K> extends MembershipListenerAdapter implements HashFunction<K> {
- Object[] nodes=null;
- private final static int HASH_SPACE=2000; // must be > max number of nodes in a cluster
-
- public Address hash(K key, List<Address> members) {
- int hash=Math.abs(key.hashCode());
- int index=hash % HASH_SPACE;
-
- if(members != null && !members.isEmpty()) {
- Object[] tmp=new Object[nodes.length];
- System.arraycopy(nodes, 0, tmp, 0, nodes.length);
- for(int i=0; i < tmp.length; i+=2) {
- if(!members.contains(tmp[i+1])) {
- tmp[i]=tmp[i+1]=null;
- }
- }
- return findFirst(tmp, index);
- }
- return findFirst(nodes, index);
- }
-
- public void viewAccepted(View new_view) {
- nodes=new Object[new_view.size() * 2];
- int index=0;
- for(Address node: new_view.getMembers()) {
- int hash=Math.abs(node.hashCode()) % HASH_SPACE;
- nodes[index++]=hash;
- nodes[index++]=node;
- }
-
- if(log.isTraceEnabled()) {
- StringBuilder sb=new StringBuilder("node mappings:\n");
- for(int i=0; i < nodes.length; i+=2) {
- sb.append(nodes[i] + ": " + nodes[i+1]).append("\n");
- }
- log.trace(sb);
- }
- }
-
- public void suspect(Address suspected_mbr) {
- }
-
- public void block() {
- }
- private static Address findFirst(Object[] array, int index) {
- Address retval=null;
- if(array == null)
- return null;
-
- for(int i=0; i < array.length; i+=2) {
- if(array[i] == null)
- continue;
- if(array[i+1] != null)
- retval=(Address)array[i+1];
- if(((Integer)array[i]) >= index)
- return (Address)array[i+1];
- }
- return retval;
- }
- }
private static class CustomMarshaller implements RpcDispatcher.Marshaller {
Oops, something went wrong.

0 comments on commit 7eb7ad6

Please sign in to comment.