All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.firebus.information.NodeInformation Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package io.firebus.information;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;

import io.firebus.Address;

public class NodeInformation 
{
	protected int nodeId;
	protected ArrayList
addresses; protected ArrayList repeaters; protected HashMap services; protected HashMap consumers; protected long lastSentDiscovery; protected long lastUpdated; protected boolean unconnectable; protected boolean unresponsive; public NodeInformation(int ni) { nodeId = ni; initialise(); } protected void initialise() { addresses = new ArrayList
(); repeaters = new ArrayList(); services = new HashMap(); consumers = new HashMap(); unconnectable = false; unresponsive = false; } public void setLastDiscoverySentTime(long t) { lastSentDiscovery = t; } public void setLastUpdatedTime(long t) { lastUpdated = t; } public void setUnconnectable() { unconnectable = true; } public void setUnresponsive() { unresponsive = true; } public void addAddress(Address a) { if(a != null && !containsAddress(a)) addresses.add(a); } public void removeAddress(Address a) { if(containsAddress(a)) addresses.remove(a); } public void addRepeater(int id) { if(!repeaters.contains(id)) repeaters.add(id); } public void addServiceInformation(String sn, ServiceInformation si) { if(!services.containsKey(sn)) services.put(sn, si); } public void addConsumerInformation(String cn, ConsumerInformation ci) { if(!consumers.containsKey(cn)) consumers.put(cn, ci); } public int getNodeId() { return nodeId; } public int getAddressCount() { return addresses.size(); } public Address getAddress(int i) { return addresses.get(i); } public boolean containsAddress(Address a) { for(int i = 0; i < addresses.size(); i++) if(addresses.get(i).equals(a)) return true; return false; } public long getLastDiscoverySentTime() { return lastSentDiscovery; } public long getLastAdvertisedTime() { return lastUpdated; } public int getRandomRepeater() { Random r = new Random(); if(repeaters.size() > 0) return repeaters.get(r.nextInt(repeaters.size())); return 0; } public ServiceInformation getServiceInformation(String sn) { return services.get(sn); } public ConsumerInformation getConsumerInformation(String cn) { return consumers.get(cn); } public boolean isUnconnectable() { return unconnectable; } public boolean isUnresponsive() { return unresponsive; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Id : " + nodeId + "\r\n"); for(int i = 0; i < addresses.size(); i++) sb.append("Address : " + addresses.get(i) + "\r\n"); for(int i = 0; i < repeaters.size(); i++) sb.append("Repeater : " + repeaters.get(i) + "\r\n"); Iterator it = services.keySet().iterator(); while(it.hasNext()) sb.append("Service : " + it.next() + "\r\n"); it = consumers.keySet().iterator(); while(it.hasNext()) sb.append("Consumers : " + it.next() + "\r\n"); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy