/** * Establishes an order between 2 ViewIds. The comparison is done on the IDs, if they are equal, we use the creator. * * @return 0 for equality, value less than 0 if smaller, greater than 0 if greater. */ public int compareTo(ViewId other) { return id > other.id ? 1 : id < other.id ? -1 : creator.compareTo(other.creator); }
private static Address readOtherAddress(DataInput in) throws Exception { short magic_number=in.readShort(); Address addr=ClassConfigurator.create(magic_number); addr.readFrom(in); return addr; }
private static void writeOtherAddress(Address addr,DataOutput out) throws Exception { short magic_number=ClassConfigurator.getMagicNumber(addr.getClass()); // write the class info if(magic_number == -1) throw new RuntimeException("magic number " + magic_number + " not found"); out.writeShort(magic_number); addr.writeTo(out); }
/** * Send the cookie first, then the our port number. If the cookie * doesn't match the receiver's cookie, the receiver will reject the * connection and close it. */ protected void sendLocalAddress(Address local_addr) throws Exception { try { // write the cookie out.write(cookie, 0, cookie.length); // write the version out.writeShort(Version.version); out.writeShort(local_addr.serializedSize()); // address size local_addr.writeTo(out); out.flush(); // needed ? updateLastAccessed(); } catch(Exception ex) { server.socket_factory.close(this.sock); connected=false; throw ex; } }
/** * Checks whether one member (unicast msg) or all members (multicast msg) have enough credits. Add those * that don't to the creditors list. Called with sent_lock held * @param dest * @param length */ private void determineCreditors(Address dest, int length) { boolean multicast=dest == null || dest.isMulticastAddress(); Address mbr; Long credits; if(multicast) { for(Map.Entry<Address,Long> entry: sent.entrySet()) { mbr=entry.getKey(); credits=entry.getValue(); if(credits <= length) creditors.add(mbr); } } else { credits=sent.get(dest); if(credits != null && credits <= length) creditors.add(dest); } }
public static int size(Address addr) { int retval=Global.BYTE_SIZE; // flags if(addr == null) return retval; if(addr instanceof UUID) { Class<? extends Address> clazz=addr.getClass(); if(clazz.equals(UUID.class) || clazz.equals(SiteUUID.class) || clazz.equals(SiteMaster.class)) return retval + addr.serializedSize(); } if(addr instanceof IpAddress) return retval + addr.serializedSize(); retval+=Global.SHORT_SIZE; // magic number retval+=addr.serializedSize(); return retval; }
public static int size(Address addr) { int retval=Global.BYTE_SIZE; // presence byte if(addr != null) retval+=addr.size() + Global.BYTE_SIZE; // plus type of address return retval; }
protected void sendLocalAddress(Address local_addr) throws Exception { try { int addr_size=local_addr.serializedSize(); int expected_size=cookie.length + Global.SHORT_SIZE*2 + addr_size; ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size +2); out.write(cookie, 0, cookie.length); out.writeShort(Version.version); out.writeShort(addr_size); // address size local_addr.writeTo(out); ByteBuffer buf=out.getByteBuffer(); send(buf, false); updateLastAccessed(); } catch(Exception ex) { close(); throw ex; } }
boolean multicast=dest == null || dest.isMulticastAddress(); long lowest=max_credits, new_credit; Long val;
public static int size(Address addr) { int retval=Global.BYTE_SIZE; // flags if(addr == null) return retval; if(addr instanceof UUID) { Class<? extends Address> clazz=addr.getClass(); if(clazz.equals(UUID.class) || clazz.equals(SiteUUID.class) || clazz.equals(SiteMaster.class)) return retval + addr.serializedSize(); } if(addr instanceof IpAddress) return retval + addr.serializedSize(); retval+=Global.SHORT_SIZE; // magic number retval+=addr.serializedSize(); return retval; }
@Override public int compareTo(AddressableNode node) { return this.address.compareTo(node.address); }
client_peer_addr.readFrom(in); updateLastAccessed(); return client_peer_addr;
out.writeByte(flags); if(streamable_addr) addr.writeTo(out); else writeOtherAddress(addr,out);
/** * Send the cookie first, then the our port number. If the cookie * doesn't match the receiver's cookie, the receiver will reject the * connection and close it. */ protected void sendLocalAddress(Address local_addr) throws Exception { try { // write the cookie out.write(cookie, 0, cookie.length); // write the version out.writeShort(Version.version); out.writeShort(local_addr.serializedSize()); // address size local_addr.writeTo(out); out.flush(); // needed ? updateLastAccessed(); } catch(Exception ex) { server.socket_factory.close(this.sock); connected=false; throw ex; } }
return; Address dest=msg.getDest(); if(dest == null || dest.isMulticastAddress()) { received.lock(); boolean locked=true;
public long serializedSize() { long retval=Global.SHORT_SIZE; // number of elements in 'senders' if(!senders.isEmpty()) { Address addr=senders.keySet().iterator().next(); int len=addr.size() + 2 * Global.BYTE_SIZE; // presence byte, IpAddress vs other address len+=Entry.SIZE; // 3 longs in one Entry retval+=len * senders.size(); } return retval; }
public int compareTo(Owner o) { return thread_id < o.thread_id? -1 : thread_id > o.thread_id? 1 : address.compareTo(o.address); }
public static Address readAddress(DataInput in) throws Exception { byte flags=in.readByte(); if(Util.isFlagSet(flags,Address.NULL)) return null; Address addr; if(Util.isFlagSet(flags,Address.UUID_ADDR)) { addr=new UUID(); addr.readFrom(in); } else if(Util.isFlagSet(flags,Address.SITE_UUID)) { addr=new SiteUUID(); addr.readFrom(in); } else if(Util.isFlagSet(flags,Address.SITE_MASTER)) { addr=new SiteMaster(); addr.readFrom(in); } else if(Util.isFlagSet(flags,Address.IP_ADDR)) { addr=new IpAddress(); addr.readFrom(in); } else if(Util.isFlagSet(flags, Address.IP_ADDR_UUID)) { addr=new IpAddressUUID(); addr.readFrom(in); } else { addr=readOtherAddress(in); } return addr; }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeUTF(this.jgAddress.getClass().getName()); try { this.jgAddress.writeTo(out); } catch (Exception e) { throw new IOException(e); } }