public void messageReceived(ChannelMessage msg) {
   if (okToProcess(msg.getOptions())) {
     if (msg.getMessage().getLength()
             == (START_DATA.length + msg.getUniqueId().length + END_DATA.length)
         && Arrays.contains(msg.getMessage().getBytesDirect(), 0, START_DATA, 0, START_DATA.length)
         && Arrays.contains(
             msg.getMessage().getBytesDirect(),
             START_DATA.length + msg.getUniqueId().length,
             END_DATA,
             0,
             END_DATA.length)) {
       UniqueId id =
           new UniqueId(
               msg.getMessage().getBytesDirect(), START_DATA.length, msg.getUniqueId().length);
       MapEntry original = (MapEntry) messages.get(id);
       if (original != null) {
         super.messageReceived(original.msg);
         messages.remove(id);
       } else
         log.warn(
             "Received a confirmation, but original message is missing. Id:"
                 + Arrays.toString(id.getBytes()));
     } else {
       UniqueId id = new UniqueId(msg.getUniqueId());
       MapEntry entry =
           new MapEntry((ChannelMessage) msg.deepclone(), id, System.currentTimeMillis());
       messages.put(id, entry);
     }
   } else {
     super.messageReceived(msg);
   }
 }
 @Override
 public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
     throws ChannelException {
   // todo, optimize, if destination.length==1, then we can do
   // msg.setOptions(msg.getOptions() & (~getOptionFlag())
   // and just send one message
   if (okToProcess(msg.getOptions())) {
     super.sendMessage(destination, msg, null);
     ChannelMessage confirmation = null;
     if (deepclone) confirmation = (ChannelMessage) msg.deepclone();
     else confirmation = (ChannelMessage) msg.clone();
     confirmation.getMessage().reset();
     UUIDGenerator.randomUUID(false, confirmation.getUniqueId(), 0);
     confirmation.getMessage().append(START_DATA, 0, START_DATA.length);
     confirmation.getMessage().append(msg.getUniqueId(), 0, msg.getUniqueId().length);
     confirmation.getMessage().append(END_DATA, 0, END_DATA.length);
     super.sendMessage(destination, confirmation, payload);
   } else {
     // turn off two phase commit
     // this wont work if the interceptor has 0 as a flag
     // since there is no flag to turn off
     // msg.setOptions(msg.getOptions() & (~getOptionFlag()));
     super.sendMessage(destination, msg, payload);
   }
 }
    public void performBasicCheck() throws RemoteException {
		try {
		    //update all alive times
		    Member[] members = super.getMembers();
		    for (int i = 0; members != null && i < members.length; i++) {
		        if (addSuspects.containsKey(members[i]) && membership.getMember(members[i]) == null) {
		            // avoid temporary adding member.
		            continue;
		        }
		        if (membership.memberAlive( (org.apache.catalina.tribes.membership.MemberImplRemoteInterface) members[i])) {
		            //we don't have this one in our membership, check to see if he/she is alive
		            if (memberAlive(members[i])) {
		                log.warn("Member added, even though we werent notified:" + members[i]);
		                super.memberAdded(members[i]);
		            } else {
		                membership.removeMember( (org.apache.catalina.tribes.membership.MemberImplRemoteInterface) members[i]);
		            }
		        }
		    }

		    //check suspect members if they are still alive,
		    //if not, simply issue the memberDisappeared message
		    org.apache.catalina.tribes.membership.MemberImplRemoteInterface[] keys = removeSuspects.keySet().toArray(new org.apache.catalina.tribes.membership.MemberImplRemoteInterface[removeSuspects.size()]);
		    for (int i = 0; i < keys.length; i++) {
		        org.apache.catalina.tribes.membership.MemberImplRemoteInterface m = keys[i];
		        if (membership.getMember(m) != null && (!memberAlive(m))) {
		            membership.removeMember(m);
		            super.memberDisappeared(m);
		            removeSuspects.remove(m);
		            if(log.isInfoEnabled())
		                log.info("Suspect member, confirmed dead.["+m+"]");
		        } else {
		            if (removeSuspectsTimeout > 0) {
		                long timeNow = System.currentTimeMillis();
		                int timeIdle = (int) ((timeNow - removeSuspects.get(m).longValue()) / 1000L);
		                if (timeIdle > removeSuspectsTimeout) {
		                    removeSuspects.remove(m); // remove suspect member
		                }
		            }
		        }
		    }

		    //check add suspects members if they are alive now,
		    //if they are, simply issue the memberAdded message
		    keys = addSuspects.keySet().toArray(new org.apache.catalina.tribes.membership.MemberImplRemoteInterface[addSuspects.size()]);
		    for (int i = 0; i < keys.length; i++) {
		        org.apache.catalina.tribes.membership.MemberImplRemoteInterface m = keys[i];
		        if ( membership.getMember(m) == null && (memberAlive(m))) {
		            membership.memberAlive(m);
		            super.memberAdded(m);
		            addSuspects.remove(m);
		            if(log.isInfoEnabled())
		                log.info("Suspect member, confirmed alive.["+m+"]");
		        }
		    }
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
Ejemplo n.º 4
0
  protected void performBasicCheck() {
    // update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
      if (addSuspects.containsKey(members[i]) && membership.getMember(members[i]) == null) {
        // avoid temporary adding member.
        continue;
      }
      if (membership.memberAlive((MemberImpl) members[i])) {
        // we don't have this one in our membership, check to see if he/she is alive
        if (memberAlive(members[i])) {
          log.warn("Member added, even though we werent notified:" + members[i]);
          super.memberAdded(members[i]);
        } else {
          membership.removeMember((MemberImpl) members[i]);
        } // end if
      } // end if
    } // for

    // check suspect members if they are still alive,
    // if not, simply issue the memberDisappeared message
    MemberImpl[] keys = removeSuspects.keySet().toArray(new MemberImpl[removeSuspects.size()]);
    for (int i = 0; i < keys.length; i++) {
      MemberImpl m = keys[i];
      if (membership.getMember(m) != null && (!memberAlive(m))) {
        membership.removeMember(m);
        super.memberDisappeared(m);
        removeSuspects.remove(m);
        if (log.isInfoEnabled()) log.info("Suspect member, confirmed dead.[" + m + "]");
      } else {
        if (removeSuspectsTimeout > 0) {
          long timeNow = System.currentTimeMillis();
          int timeIdle = (int) ((timeNow - removeSuspects.get(m)) / 1000L);
          if (timeIdle > removeSuspectsTimeout) {
            removeSuspects.remove(m); // remove suspect member
          }
        }
      }
    }

    // check add suspects members if they are alive now,
    // if they are, simply issue the memberAdded message
    keys = addSuspects.keySet().toArray(new MemberImpl[addSuspects.size()]);
    for (int i = 0; i < keys.length; i++) {
      MemberImpl m = keys[i];
      if (membership.getMember(m) == null && (memberAlive(m))) {
        membership.memberAlive(m);
        super.memberAdded(m);
        addSuspects.remove(m);
        if (log.isInfoEnabled()) log.info("Suspect member, confirmed alive.[" + m + "]");
      } // end if
    }
  }
    @Override
    public void memberAdded(Member member) throws RemoteException {
		try {
		    if ( membership == null ) setupMembership();
		    boolean notify = false;
		    synchronized (membership) {
		        if (removeSuspects.containsKey(member)) {
		            //previously marked suspect, system below picked up the member again
		            removeSuspects.remove(member);
		        } else if (membership.getMember(member) == null){
		            //if we add it here, then add it upwards too
		            //check to see if it is alive
		            if (memberAlive(member)) {
		                membership.memberAlive( (org.apache.catalina.tribes.membership.MemberImplRemoteInterface) member);
		                notify = true;
		            } else {
		                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
		            }
		        }
		    }
		    if ( notify ) super.memberAdded(member);
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
Ejemplo n.º 6
0
 @Override
 public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
     throws ChannelException {
   if (!okToProcess(msg.getOptions())) {
     super.sendMessage(destination, msg, payload);
     return;
   }
   ChannelException cx = null;
   for (int i = 0; i < destination.length; i++) {
     try {
       int nr = 0;
       try {
         outLock.writeLock().lock();
         nr = incCounter(destination[i]);
       } finally {
         outLock.writeLock().unlock();
       }
       // reduce byte copy
       msg.getMessage().append(nr);
       try {
         getNext().sendMessage(new Member[] {destination[i]}, msg, payload);
       } finally {
         msg.getMessage().trim(4);
       }
     } catch (ChannelException x) {
       if (cx == null) cx = x;
       cx.addFaultyMember(x.getFaultyMembers());
     }
   } // for
   if (cx != null) throw cx;
 }
    @Override
    public void heartbeat() throws RemoteException {
		try {
		    super.heartbeat();
		    checkMembers(false);
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
Ejemplo n.º 8
0
 @Override
 public void memberDisappeared(Member member) {
   // reset counters - lock free
   incounter.remove(member);
   outcounter.remove(member);
   // clear the remaining queue
   processLeftOvers(member, true);
   // notify upwards
   super.memberDisappeared(member);
 }
Ejemplo n.º 9
0
  /**
   * @param order MessageOrder
   * @return boolean - true if a message expired and was processed
   */
  protected boolean processIncoming(MessageOrder order) {
    boolean result = false;
    Member member = order.getMessage().getAddress();
    Counter cnt = getInCounter(member);

    MessageOrder tmp = incoming.get(member);
    if (tmp != null) {
      order = MessageOrder.add(tmp, order);
    }

    while ((order != null) && (order.getMsgNr() <= cnt.getCounter())) {
      // we are right on target. process orders
      if (order.getMsgNr() == cnt.getCounter()) cnt.inc();
      else if (order.getMsgNr() > cnt.getCounter()) cnt.setCounter(order.getMsgNr());
      super.messageReceived(order.getMessage());
      order.setMessage(null);
      order = order.next;
    }
    MessageOrder head = order;
    MessageOrder prev = null;
    tmp = order;
    // flag to empty out the queue when it larger than maxQueue
    boolean empty = order != null ? order.getCount() >= maxQueue : false;
    while (tmp != null) {
      // process expired messages or empty out the queue
      if (tmp.isExpired(expire) || empty) {
        // reset the head
        if (tmp == head) head = tmp.next;
        cnt.setCounter(tmp.getMsgNr() + 1);
        if (getForwardExpired()) super.messageReceived(tmp.getMessage());
        tmp.setMessage(null);
        tmp = tmp.next;
        if (prev != null) prev.next = tmp;
        result = true;
      } else {
        prev = tmp;
        tmp = tmp.next;
      }
    }
    if (head == null) incoming.remove(member);
    else incoming.put(member, head);
    return result;
  }
 protected void performForcedCheck() {
   // update all alive times
   Member[] members = super.getMembers();
   for (int i = 0; members != null && i < members.length; i++) {
     if (memberAlive(members[i])) {
       if (membership.memberAlive((MemberImpl) members[i])) super.memberAdded(members[i]);
       addSuspects.remove(members[i]);
     } else {
       if (membership.getMember(members[i]) != null) {
         membership.removeMember((MemberImpl) members[i]);
         removeSuspects.remove(members[i]);
         if (members[i] instanceof StaticMember) {
           addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
         }
         super.memberDisappeared(members[i]);
       }
     }
   }
 }
  @Override
  public void messageReceived(ChannelMessage msg) {
    // catch incoming
    boolean process = true;
    if (okToProcess(msg.getOptions())) {
      // check to see if it is a testMessage, if so, process = false
      process =
          ((msg.getMessage().getLength() != TCP_FAIL_DETECT.length)
              || (!Arrays.equals(TCP_FAIL_DETECT, msg.getMessage().getBytes())));
    } // end if

    // ignore the message, it doesnt have the flag set
    if (process) super.messageReceived(msg);
    else if (log.isDebugEnabled()) log.debug("Received a failure detector packet:" + msg);
  }
Ejemplo n.º 12
0
 @Override
 public void messageReceived(ChannelMessage msg) {
   if (!okToProcess(msg.getOptions())) {
     super.messageReceived(msg);
     return;
   }
   int msgnr =
       XByteBuffer.toInt(msg.getMessage().getBytesDirect(), msg.getMessage().getLength() - 4);
   msg.getMessage().trim(4);
   MessageOrder order = new MessageOrder(msgnr, (ChannelMessage) msg.deepclone());
   try {
     inLock.writeLock().lock();
     if (processIncoming(order)) processLeftOvers(msg.getAddress(), false);
   } finally {
     inLock.writeLock().unlock();
   }
 }
	public static void startManagers() {
		ChannelInterceptorBase.startManagers();
		try {
			if (gerenciadornuvem0 == null)
				gerenciadornuvem0 = (Gerenciadornuvem0Interface) Naming
						.lookup("rmi://0:1099/gerenciadornuvem0");
			if (gerenciadornuvem1 == null)
				gerenciadornuvem1 = (Gerenciadornuvem1Interface) Naming
						.lookup("rmi://1:1099/gerenciadornuvem1");
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}
 @Override
 public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
     throws ChannelException {
   try {
     super.sendMessage(destination, msg, payload);
   } catch (ChannelException cx) {
     ChannelExceptionFaultyMember[] mbrs = cx.getFaultyMembers();
     for (int i = 0; i < mbrs.length; i++) {
       if (mbrs[i].getCause() != null
           && (!(mbrs[i].getCause()
               instanceof RemoteProcessException))) { // RemoteProcessException's are ok
         this.memberDisappeared(mbrs[i].getMember());
       } // end if
     } // for
     throw cx;
   }
 }
 public void heartbeat() {
   try {
     long now = System.currentTimeMillis();
     Map.Entry[] entries =
         (Map.Entry[]) messages.entrySet().toArray(new Map.Entry[messages.size()]);
     for (int i = 0; i < entries.length; i++) {
       MapEntry entry = (MapEntry) entries[i].getValue();
       if (entry.expired(now, expire)) {
         if (log.isInfoEnabled()) log.info("Message [" + entry.id + "] has expired. Removing.");
         messages.remove(entry.id);
       } // end if
     }
   } catch (Exception x) {
     log.warn("Unable to perform heartbeat on the TwoPhaseCommit interceptor.", x);
   } finally {
     super.heartbeat();
   }
 }
    @Override
    public void memberDisappeared(Member member) throws RemoteException {
		try {
		    if ( membership == null ) setupMembership();
		    boolean notify = false;
		    boolean shutdown = Arrays.equals(member.getCommand(),Member.SHUTDOWN_PAYLOAD);
		    if ( !shutdown )
		        if(log.isInfoEnabled())
		            log.info("Received memberDisappeared["+member+"] message. Will verify.");
		    synchronized (membership) {
		        if (!membership.contains(member)) {
		            if(log.isInfoEnabled())
		                log.info("Verification complete. Member already disappeared["+member+"]");
		            return;
		        }
		        //check to see if the member really is gone
		        //if the payload is not a shutdown message
		        if (shutdown || !memberAlive(member)) {
		            //not correct, we need to maintain the map
		            membership.removeMember( (org.apache.catalina.tribes.membership.MemberImplRemoteInterface) member);
		            removeSuspects.remove(member);
		            if (member instanceof org.apache.catalina.tribes.membership.StaticMemberRemoteInterface) {
		                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
		            }
		            notify = true;
		        } else {
		            //add the member as suspect
		            removeSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
		        }
		    }
		    if ( notify ) {
		        if(log.isInfoEnabled())
		            log.info("Verification complete. Member disappeared["+member+"]");
		        super.memberDisappeared(member);
		    } else {
		        if(log.isInfoEnabled())
		            log.info("Verification complete. Member still alive["+member+"]");

		    }
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
    @Override
    public void sendMessage(Member[] destination, ChannelMessage msg, org.apache.catalina.tribes.group.InterceptorPayloadRemoteInterface payload) throws ChannelException, RemoteException {
		try {
		    try {
		        super.sendMessage(destination, msg, payload);
		    }catch ( ChannelException cx ) {
		    	org.apache.catalina.tribes.ChannelExceptionFaultyMemberRemoteInterface[] mbrs = cx.getFaultyMembers();
		        for ( int i=0; i<mbrs.length; i++ ) {
		            if ( mbrs[i].getCause()!=null &&
		                 (!(mbrs[i].getCause() instanceof RemoteProcessException)) ) {//RemoteProcessException's are ok
		                this.memberDisappeared(mbrs[i].getMember());
		            }//end if
		        }//for
		        throw cx;
		    }
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
 @Override
 public void memberAdded(Member member) {
   if (membership == null) setupMembership();
   boolean notify = false;
   synchronized (membership) {
     if (removeSuspects.containsKey(member)) {
       // previously marked suspect, system below picked up the member again
       removeSuspects.remove(member);
     } else if (membership.getMember(member) == null) {
       // if we add it here, then add it upwards too
       // check to see if it is alive
       if (memberAlive(member)) {
         membership.memberAlive((MemberImpl) member);
         notify = true;
       } else {
         addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
       }
     }
   }
   if (notify) super.memberAdded(member);
 }
    public void performForcedCheck() throws RemoteException {
		try {
		    //update all alive times
		    Member[] members = super.getMembers();
		    for (int i = 0; members != null && i < members.length; i++) {
		        if (memberAlive(members[i])) {
		            if (membership.memberAlive((org.apache.catalina.tribes.membership.MemberImplRemoteInterface)members[i])) super.memberAdded(members[i]);
		            addSuspects.remove(members[i]);
		        } else {
		            if (membership.getMember(members[i])!=null) {
		                membership.removeMember((org.apache.catalina.tribes.membership.MemberImplRemoteInterface)members[i]);
		                removeSuspects.remove(members[i]);
		                if (members[i] instanceof org.apache.catalina.tribes.membership.StaticMemberRemoteInterface) {
		                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
		                }
		                super.memberDisappeared(members[i]);
		            }
		        }
		    }

		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
Ejemplo n.º 20
0
 @Override
 public void memberAdded(Member member) {
   // notify upwards
   super.memberAdded(member);
 }
 @Override
 public void heartbeat() {
   super.heartbeat();
   checkMembers(false);
 }