Java Code Examples for javolution.util.FastMap#Entry

The following examples show how to use javolution.util.FastMap#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KnownList.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public int doOnAllNpcs(Visitor<Npc> visitor, int iterationLimit) {
	int counter = 0;
	try {
		for (FastMap.Entry<Integer, VisibleObject> e = knownObjects.head(), mapEnd = knownObjects.tail(); (e = e.getNext()) != mapEnd;) {
			VisibleObject newObject = e.getValue();
			if (newObject instanceof Npc) {
				if ((++counter) == iterationLimit) {
					break;
				}
				visitor.visit((Npc) newObject);
			}
		}
	}
	catch (Exception ex) {
		// log.error("Exception when running visitor on all npcs" + ex);
	}
	return counter;
}
 
Example 2
Source File: KnownList.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public int doOnAllNpcsWithOwner(VisitorWithOwner<Npc, VisibleObject> visitor, int iterationLimit) {
	int counter = 0;
	try {
		for (FastMap.Entry<Integer, VisibleObject> e = knownObjects.head(), mapEnd = knownObjects.tail(); (e = e.getNext()) != mapEnd;) {
			VisibleObject newObject = e.getValue();
			if (newObject instanceof Npc) {
				if ((++counter) == iterationLimit) {
					break;
				}
				visitor.visit((Npc) newObject, owner);
			}
		}
	}
	catch (Exception ex) {
		// log.error("Exception when running visitor on all npcs" + ex);
	}
	return counter;
}
 
Example 3
Source File: KnownList.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void doOnAllPlayers(Visitor<Player> visitor) {
	if (knownPlayers == null) {
		return;
	}
	try {
		for (FastMap.Entry<Integer, Player> e = knownPlayers.head(), mapEnd = knownPlayers.tail(); (e = e.getNext()) != mapEnd;) {
			Player player = e.getValue();
			if (player != null) {
				visitor.visit(player);
			}
		}
	}
	catch (Exception ex) {
		// log.error("Exception when running visitor on all players" + ex);
	}
}
 
Example 4
Source File: MoveTaskManager.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
	final FastList<Creature> arrivedCreatures = FastList.newInstance();
	final FastList<Creature> followingCreatures = FastList.newInstance();

	for (FastMap.Entry<Integer, Creature> e = movingCreatures.head(), mapEnd = movingCreatures.tail(); (e = e.getNext()) != mapEnd;) {
		Creature creature = e.getValue();
		creature.getMoveController().moveToDestination();
		if (creature.getAi2().poll(AIQuestion.DESTINATION_REACHED)) {
			movingCreatures.remove(e.getKey());
			arrivedCreatures.add(e.getValue());
		}
		else {
			followingCreatures.add(e.getValue());
		}
	}
	targetReachedManager.executeAll(arrivedCreatures);
	targetTooFarManager.executeAll(followingCreatures);
	FastList.recycle(arrivedCreatures);
	FastList.recycle(followingCreatures);

}
 
Example 5
Source File: KnownList.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void doOnAllObjects(Visitor<VisibleObject> visitor) {
	try {
		for (FastMap.Entry<Integer, VisibleObject> e = knownObjects.head(), mapEnd = knownObjects.tail(); (e = e.getNext()) != mapEnd;) {
			VisibleObject newObject = e.getValue();
			if (newObject != null) {
				visitor.visit(newObject);
			}
		}
	}
	catch (Exception ex) {
		// log.error("Exception when running visitor on all objects" + ex);
	}
}
 
Example 6
Source File: World.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param visitor
 */
public void doOnAllObjects(Visitor<VisibleObject> visitor) {
	try {
		for (FastMap.Entry<Integer, VisibleObject> e = allObjects.head(), mapEnd = allObjects.tail(); (e = e.getNext()) != mapEnd;) {
			VisibleObject object = e.getValue();
			if (object != null) {
				visitor.visit(object);
			}
		}
	}
	catch (Exception ex) {
		log.error("Exception when running visitor on all objects", ex);
	}
}
 
Example 7
Source File: KnownList.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find objects that are in visibility range.
 */
protected void findVisibleObjects() {
	if (owner == null || !owner.isSpawned()) {
		return;
	}

	MapRegion[] regions = owner.getActiveRegion().getNeighbours();
	for (int i = 0; i < regions.length; i++) {
		MapRegion r = regions[i];
		FastMap<Integer, VisibleObject> objects = r.getObjects();
		for (FastMap.Entry<Integer, VisibleObject> e = objects.head(), mapEnd = objects.tail(); (e = e.getNext()) != mapEnd;) {
			VisibleObject newObject = e.getValue();
			if (newObject == owner || newObject == null) {
				continue;
			}

			if (!isAwareOf(newObject)) {
				continue;
			}
			if (knownObjects.containsKey(newObject.getObjectId())) {
				continue;
			}

			if (!checkObjectInRange(newObject) && !newObject.getKnownList().checkReversedObjectInRange(owner)) {
				continue;
			}

			/**
			 * New object is not known.
			 */
			if (add(newObject)) {
				newObject.getKnownList().add(owner);
			}
		}
	}
}
 
Example 8
Source File: SiegeZoneInstance.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void doOnAllPlayers(Visitor<Player> visitor) {
	try {
		for (FastMap.Entry<Integer, Player> e = players.head(), mapEnd = players.tail(); (e = e.getNext()) != mapEnd;) {
			Player player = e.getValue();
			if (player != null) {
				visitor.visit(player);
			}
		}
	}
	catch (Exception ex) {
		log.error("Exception when running visitor on all players" + ex);
	}
}
 
Example 9
Source File: PlayerMoveTaskManager.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
	for (FastMap.Entry<Integer, Creature> e = movingPlayers.head(), mapEnd = movingPlayers.tail(); (e = e.getNext()) != mapEnd;) {
		Creature player = e.getValue();
		player.getMoveController().moveToDestination();
	}
}
 
Example 10
Source File: AggroList.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return most hated creature
 */
public Creature getMostHated() {
	if (aggroList.isEmpty()) {
		return null;
	}

	Creature mostHated = null;
	int maxHate = 0;

	for (FastMap.Entry<Integer, AggroInfo> e = aggroList.head(), mapEnd = aggroList.tail(); (e = e.getNext()) != mapEnd;) {
		AggroInfo ai = e.getValue();
		if (ai == null) {
			continue;
		}

		// aggroList will never contain anything but creatures
		Creature attacker = (Creature) ai.getAttacker();

		if (attacker.getLifeStats().isAlreadyDead()) {
			ai.setHate(0);
		}

		if (ai.getHate() > maxHate) {
			mostHated = attacker;
			maxHate = ai.getHate();
		}
	}

	return mostHated;
}
 
Example 11
Source File: ShieldController.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void disable() {
	for (FastMap.Entry<Integer, ActionObserver> e = observed.head(), mapEnd = observed.tail(); (e = e.getNext()) != mapEnd;) {
		ActionObserver observer = observed.remove(e.getKey());
		Player player = World.getInstance().findPlayer(e.getKey());
		if (player != null) {
			player.getObserveController().removeObserver(observer);
		}
	}
}
 
Example 12
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Association addAssociation(String hostAddress, int hostPort, String peerAddress, int peerPort, String assocName,
        IpChannelType ipChannelType, String[] extraHostAddresses) throws Exception {

    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

    if (hostAddress == null) {
        throw new Exception("Host address cannot be null");
    }

    if (hostPort < 0) {
        throw new Exception("Host port cannot be less than 0");
    }

    if (peerAddress == null) {
        throw new Exception("Peer address cannot be null");
    }

    if (peerPort < 1) {
        throw new Exception("Peer port cannot be less than 1");
    }

    if (assocName == null) {
        throw new Exception("Association name cannot be null");
    }

    synchronized (this) {
        for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n
                .getNext()) != end;) {
            Association associationTemp = n.getValue();

            if (assocName.equals(associationTemp.getName())) {
                throw new Exception(String.format("Already has association=%s", associationTemp.getName()));
            }

            if (peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
                throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d",
                        associationTemp.getName(), peerAddress, peerPort));
            }

            if (hostAddress.equals(associationTemp.getHostAddress()) && associationTemp.getHostPort() == hostPort) {
                throw new Exception(String.format("Already has association=%s with same host address=%s and port=%d",
                        associationTemp.getName(), hostAddress, hostPort));
            }

        }

        NettyAssociationImpl association = new NettyAssociationImpl(hostAddress, hostPort, peerAddress, peerPort,
                assocName, ipChannelType, extraHostAddresses);
        association.setManagement(this);

        NettyAssociationMap<String, Association> newAssociations = new NettyAssociationMap<String, Association>();
        newAssociations.putAll(this.associations);
        newAssociations.put(assocName, association);
        this.associations = newAssociations;
        // associations.put(assocName, association);

        this.store();

        for (ManagementEventListener lstr : managementEventListeners) {
            try {
                lstr.onAssociationAdded(association);
            } catch (Throwable ee) {
                logger.error("Exception while invoking onAssociationAdded", ee);
            }
        }

        if (logger.isInfoEnabled()) {
            logger.info(String.format("Added Associoation=%s of type=%s", association.getName(),
                    association.getAssociationType()));
        }

        return association;
    }
}
 
Example 13
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Association addServerAssociation(String peerAddress, int peerPort, String serverName, String assocName,
        IpChannelType ipChannelType) throws Exception {
    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

    if (peerAddress == null) {
        throw new Exception("Peer address cannot be null");
    }

    if (peerPort < 0) {
        throw new Exception("Peer port cannot be less than 0");
    }

    if (serverName == null) {
        throw new Exception("Server name cannot be null");
    }

    if (assocName == null) {
        throw new Exception("Association name cannot be null");
    }

    synchronized (this) {
        if (this.associations.get(assocName) != null) {
            throw new Exception(String.format("Already has association=%s", assocName));
        }

        Server server = null;

        for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
            Server serverTemp = n.getValue();
            if (serverTemp.getName().equals(serverName)) {
                server = serverTemp;
            }
        }

        if (server == null) {
            throw new Exception(String.format("No Server found for name=%s", serverName));
        }

        for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n
                .getNext()) != end;) {
            Association associationTemp = n.getValue();
            
            if (associationTemp.getServerName().equals(server.getName()) && peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
                throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d",
                        associationTemp.getName(), peerAddress, peerPort));
            }
        }

        if (server.getIpChannelType() != ipChannelType)
            throw new Exception(String.format("Server and Accociation has different IP channel type"));

        NettyAssociationImpl association = new NettyAssociationImpl(peerAddress, peerPort, serverName, assocName,
                ipChannelType);
        association.setManagement(this);

        NettyAssociationMap<String, Association> newAssociations = new NettyAssociationMap<String, Association>();
        newAssociations.putAll(this.associations);
        newAssociations.put(assocName, association);
        this.associations = newAssociations;
        // this.associations.put(assocName, association);

        FastList<String> newAssociations2 = new FastList<String>();
        newAssociations2.addAll(((NettyServerImpl) server).associations);
        newAssociations2.add(assocName);
        ((NettyServerImpl) server).associations = newAssociations2;
        // ((ServerImpl) server).associations.add(assocName);

        this.store();

        for (ManagementEventListener lstr : managementEventListeners) {
            try {
                lstr.onAssociationAdded(association);
            } catch (Throwable ee) {
                logger.error("Exception while invoking onAssociationAdded", ee);
            }
        }

        if (logger.isInfoEnabled()) {
            logger.info(String.format("Added Associoation=%s of type=%s", association.getName(),
                    association.getAssociationType()));
        }

        return association;
    }
}
 
Example 14
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void modifyAssociation(String hostAddress, Integer hostPort, String peerAddress, Integer peerPort, String assocName,	IpChannelType ipChannelType, String[] extraHostAddresses) throws Exception {

	boolean isModified = false;
	if (!this.started) {
		throw new Exception(String.format("Management=%s not started", this.name));
	}

	if (hostPort != null && (hostPort < 1 || hostPort > 65535)) {
		throw new Exception("Host port cannot be less than 1 or more than 65535. But was : " + hostPort);
	}

	if (peerPort != null && (peerPort < 1 || peerPort > 65535)) {
		throw new Exception("Peer port cannot be less than 1 or more than 65535. But was : " + peerPort);
	}

	if (assocName == null) {
		throw new Exception("Association name cannot be null");
	}
	synchronized (this) {
		for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
			Association associationTemp = n.getValue();

			if (peerAddress !=null && peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
				throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d", associationTemp.getName(),
						peerAddress, peerPort));
			}

			if (hostAddress !=null && hostAddress.equals(associationTemp.getHostAddress()) && associationTemp.getHostPort() == hostPort) {
				throw new Exception(String.format("Already has association=%s with same host address=%s and port=%d", associationTemp.getName(),
						hostAddress, hostPort));
			}

		}

		AssociationImpl association = (AssociationImpl) this.associations.get(assocName);

		if(hostAddress!=null)
		{
			association.setHostAddress(hostAddress);
			isModified = true;
		}

		if(hostPort!= null)
		{
			association.setHostPort(hostPort);
			isModified = true;
		}

		if(peerAddress!=null)
		{
			association.setPeerAddress(peerAddress);
			isModified = true;
		}

		if(peerPort!= null)
		{
			association.setPeerPort(peerPort);
			isModified = true;
		}

		if(ipChannelType!=null)
		{
			association.setIpChannelType(ipChannelType);
			isModified = true;
		}

		if(extraHostAddresses!=null)
		{
			association.setExtraHostAddresses(extraHostAddresses);
			isModified = true;
		}

		if(association.isConnected() && isModified)
		{
			association.stop();
			association.start();
		}

		this.store();

		for (ManagementEventListener lstr : managementEventListeners) {
			try {
				lstr.onAssociationModified((Association)association);
			} catch (Throwable ee) {
				logger.error("Exception while invoking onAssociationModified", ee);
			}
		}

	}

}
 
Example 15
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
public AssociationImpl addAssociation(String hostAddress, int hostPort, String peerAddress, int peerPort, String assocName, IpChannelType ipChannelType,
		String[] extraHostAddresses) throws Exception {

	if (!this.started) {
		throw new Exception(String.format("Management=%s not started", this.name));
	}

	if (hostAddress == null) {
		throw new Exception("Host address cannot be null");
	}

	if (hostPort < 0) {
		throw new Exception("Host port cannot be less than 0");
	}

	if (peerAddress == null) {
		throw new Exception("Peer address cannot be null");
	}

	if (peerPort < 1) {
		throw new Exception("Peer port cannot be less than 1");
	}

	if (assocName == null) {
		throw new Exception("Association name cannot be null");
	}

	synchronized (this) {
		for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
			Association associationTemp = n.getValue();

			if (assocName.equals(associationTemp.getName())) {
				throw new Exception(String.format("Already has association=%s", associationTemp.getName()));
			}

			if (peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
				throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d", associationTemp.getName(),
						peerAddress, peerPort));
			}

			if (hostAddress.equals(associationTemp.getHostAddress()) && associationTemp.getHostPort() == hostPort) {
				throw new Exception(String.format("Already has association=%s with same host address=%s and port=%d", associationTemp.getName(),
						hostAddress, hostPort));
			}

		}

		AssociationImpl association = new AssociationImpl(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses);
		association.setManagement(this);

		AssociationMap<String, Association> newAssociations = new AssociationMap<String, Association>();
		newAssociations.putAll(this.associations);
		newAssociations.put(assocName, association);
		this.associations = newAssociations;
		// associations.put(assocName, association);

		this.store();

		for (ManagementEventListener lstr : managementEventListeners) {
			try {
				lstr.onAssociationAdded(association);
			} catch (Throwable ee) {
				logger.error("Exception while invoking onAssociationAdded", ee);
			}
		}

		if (logger.isInfoEnabled()) {
			logger.info(String.format("Added Associoation=%s of type=%s", association.getName(), association.getAssociationType()));
		}

		return association;
	}
}
 
Example 16
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
public AssociationImpl addServerAssociation(String peerAddress, int peerPort, String serverName, String assocName, IpChannelType ipChannelType)
		throws Exception {

	if (!this.started) {
		throw new Exception(String.format("Management=%s not started", this.name));
	}

	if (peerAddress == null) {
		throw new Exception("Peer address cannot be null");
	}

	if (peerPort < 1) {
		throw new Exception("Peer port cannot be less than 1");
	}

	if (serverName == null) {
		throw new Exception("Server name cannot be null");
	}

	if (assocName == null) {
		throw new Exception("Association name cannot be null");
	}

	synchronized (this) {
		if (this.associations.get(assocName) != null) {
			throw new Exception(String.format("Already has association=%s", assocName));
		}

		Server server = null;

		for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
			Server serverTemp = n.getValue();
			if (serverTemp.getName().equals(serverName)) {
				server = serverTemp;
			}
		}

		if (server == null) {
			throw new Exception(String.format("No Server found for name=%s", serverName));
		}

		for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
			Association associationTemp = n.getValue();

			if (peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
				throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d", associationTemp.getName(),
						peerAddress, peerPort));
			}
		}

		if (server.getIpChannelType() != ipChannelType)
			throw new Exception(String.format("Server and Accociation has different IP channel type"));

		AssociationImpl association = new AssociationImpl(peerAddress, peerPort, serverName, assocName, ipChannelType);
		association.setManagement(this);

		AssociationMap<String, Association> newAssociations = new AssociationMap<String, Association>();
		newAssociations.putAll(this.associations);
		newAssociations.put(assocName, association);
		this.associations = newAssociations;
		// this.associations.put(assocName, association);

		FastList<String> newAssociations2 = new FastList<String>();
		newAssociations2.addAll(((ServerImpl) server).associations);
		newAssociations2.add(assocName);
		((ServerImpl) server).associations = newAssociations2;
		// ((ServerImpl) server).associations.add(assocName);

		this.store();

		for (ManagementEventListener lstr : managementEventListeners) {
			try {
				lstr.onAssociationAdded(association);
			} catch (Throwable ee) {
				logger.error("Exception while invoking onAssociationAdded", ee);
			}
		}

		if (logger.isInfoEnabled()) {
			logger.info(String.format("Added Associoation=%s of type=%s", association.getName(), association.getAssociationType()));
		}

		return association;
	}
}
 
Example 17
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
	public void load() throws FileNotFoundException {
		XMLObjectReader reader = null;
		try {
			reader = XMLObjectReader.newInstance(new FileInputStream(persistFile.toString()));
			reader.setBinding(binding);

            try {
                Integer vali = reader.read(CONNECT_DELAY_PROP, Integer.class);
                if (vali != null)
                    this.connectDelay = vali;
//                this.workerThreads = reader.read(WORKER_THREADS_PROP, Integer.class);
//                this.singleThread = reader.read(SINGLE_THREAD_PROP, Boolean.class);
                vali = reader.read(WORKER_THREADS_PROP, Integer.class);
                Boolean valb = reader.read(SINGLE_THREAD_PROP, Boolean.class);

                Double valTH1 = reader.read(NettySctpManagementImpl.CONG_CONTROL_DELAY_THRESHOLD_1, Double.class);
                Double valTH2 = reader.read(NettySctpManagementImpl.CONG_CONTROL_DELAY_THRESHOLD_2, Double.class);
                Double valTH3 = reader.read(NettySctpManagementImpl.CONG_CONTROL_DELAY_THRESHOLD_3, Double.class);
                Double valTB1 = reader
                        .read(NettySctpManagementImpl.CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_1, Double.class);
                Double valTB2 = reader
                        .read(NettySctpManagementImpl.CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_2, Double.class);
                Double valTB3 = reader
                        .read(NettySctpManagementImpl.CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_3, Double.class);

                // TODO: revive this test when we introduce of parameters persistense 
//                Boolean valB = reader.read(NettySctpManagementImpl.OPTION_SCTP_DISABLE_FRAGMENTS, Boolean.class);
//                Integer valI = reader.read(NettySctpManagementImpl.OPTION_SCTP_FRAGMENT_INTERLEAVE, Integer.class);
//                Integer valI_In = reader.read(NettySctpManagementImpl.OPTION_SCTP_INIT_MAXSTREAMS_IN, Integer.class);
//                Integer valI_Out = reader.read(NettySctpManagementImpl.OPTION_SCTP_INIT_MAXSTREAMS_OUT, Integer.class);
//                valB = reader.read(NettySctpManagementImpl.OPTION_SCTP_NODELAY, Boolean.class);
//                valI = reader.read(NettySctpManagementImpl.OPTION_SO_SNDBUF, Integer.class);
//                valI = reader.read(NettySctpManagementImpl.OPTION_SO_RCVBUF, Integer.class);
//                valI = reader.read(NettySctpManagementImpl.OPTION_SO_LINGER, Integer.class);

            } catch (java.lang.NullPointerException npe) {
                // ignore.
                // For backward compatibility we can ignore if these values are not defined
            }			

			this.servers = reader.read(SERVERS, FastList.class);

			for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
				Server serverTemp = n.getValue();
				((ServerImpl) serverTemp).setManagement(this);
				if (serverTemp.isStarted()) {
					try {
						((ServerImpl) serverTemp).start();
					} catch (Exception e) {
						logger.error(String.format("Error while initiating Server=%s", serverTemp.getName()), e);
					}
				}
			}

			this.associations = reader.read(ASSOCIATIONS, AssociationMap.class);
			for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
				AssociationImpl associationTemp = (AssociationImpl) n.getValue();
				associationTemp.setManagement(this);
			}

		} catch (XMLStreamException ex) {
			// this.logger.info(
			// "Error while re-creating Linksets from persisted file", ex);
		}
	}
 
Example 18
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void modifyAssociation(String hostAddress, Integer hostPort, String peerAddress, Integer peerPort, String assocName,	IpChannelType ipChannelType, String[] extraHostAddresses) throws Exception {

	boolean isModified = false;
	if (!this.started) {
		throw new Exception(String.format("Management=%s not started", this.name));
	}

	if (hostPort != null && (hostPort < 1 || hostPort > 65535)) {
		throw new Exception("Host port cannot be less than 1 or more than 65535. But was : " + hostPort);
	}

	if (peerPort != null && (peerPort < 1 || peerPort > 65535)) {
		throw new Exception("Peer port cannot be less than 1 or more than 65535. But was : " + peerPort);
	}

	if (assocName == null) {
		throw new Exception("Association name cannot be null");
	}
	synchronized (this) {
		for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
			Association associationTemp = n.getValue();
			if(assocName.equals(associationTemp.getName()))
			    continue;

			if (peerAddress !=null && peerAddress.equals(associationTemp.getPeerAddress()) && associationTemp.getPeerPort() == peerPort) {
				throw new Exception(String.format("Already has association=%s with same peer address=%s and port=%d", associationTemp.getName(),
						peerAddress, peerPort));
			}

			if (hostAddress !=null && hostAddress.equals(associationTemp.getHostAddress()) && associationTemp.getHostPort() == hostPort) {
				throw new Exception(String.format("Already has association=%s with same host address=%s and port=%d", associationTemp.getName(),
						hostAddress, hostPort));
			}

		}

		NettyAssociationImpl association = (NettyAssociationImpl) this.associations.get(assocName);

		if(hostAddress!=null)
		{
			association.setHostAddress(hostAddress);
			isModified = true;
		}

		if(hostPort!= null)
		{
			association.setHostPort(hostPort);
			isModified = true;
		}

		if(peerAddress!=null)
		{
			association.setPeerAddress(peerAddress);
			isModified = true;
		}

		if(peerPort!= null)
		{
			association.setPeerPort(peerPort);
			isModified = true;
		}

		if(ipChannelType!=null)
		{
			association.setIpChannelType(ipChannelType);
			isModified = true;
		}

		if(extraHostAddresses!=null)
		{
			association.setExtraHostAddresses(extraHostAddresses);
			isModified = true;
		}

		if(association.isConnected() && isModified)
		{
			association.stop();
			association.start();
		}

		this.store();

		for (ManagementEventListener lstr : managementEventListeners) {
			try {
				lstr.onAssociationModified((Association)association);
			} catch (Throwable ee) {
				logger.error("Exception while invoking onAssociationModified", ee);
			}
		}
	}
}
 
Example 19
Source File: SM_INSTANCE_INFO.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void writeImpl(AionConnection con) {
	boolean hasTeam = playerTeam != null;
	writeC(!isAnswer ? 2 : hasTeam ? 1 : 0);
	writeC(cooldownId);
	writeD(0);
	writeH(1);
	if (cooldownId == 0) {
		writeD(player.getObjectId());
		writeH(DataManager.INSTANCE_COOLTIME_DATA.size());
		PortalCooldownList cooldownList = player.getPortalCooldownList();
		for (FastMap.Entry<Integer, InstanceCooltime> e = DataManager.INSTANCE_COOLTIME_DATA.getAllInstances().head(), end = DataManager.INSTANCE_COOLTIME_DATA.getAllInstances().tail(); (e = e.getNext()) != end;) {
			writeD(e.getValue().getId());
			writeD(0x0);
			if (cooldownList.getPortalCooldown(e.getValue().getWorldId()) == 0) {
				writeD(0x0);
			}
			else {
				writeD((int) (cooldownList.getPortalCooldown(e.getValue().getWorldId()) - System.currentTimeMillis()) / 1000);
			}
			writeD(DataManager.INSTANCE_COOLTIME_DATA.getInstanceEntranceCountByWorldId(e.getKey()));
			writeD(cooldownList.getPortalCooldownItem(e.getValue().getWorldId()) != null ? cooldownList.getPortalCooldownItem(e.getValue().getWorldId()).getEntryCount() * -1 : 0);
			writeD(0); // 4.9
			writeD(0); // 4.9
			writeD(0); // Unk 5.1
			writeD(0); // Unk 6.x
			writeC(1); // activated
		}
		writeS(player.getName());
	}
	else {
		writeD(player.getObjectId());
		writeH(player.getPortalCooldownList().size()); // TEST
		for (int i = 0; i < player.getPortalCooldownList().size(); i++) {
			writeD(cooldownId); // InstanceID
			writeD(0);
			writeD(0);
			writeD(DataManager.INSTANCE_COOLTIME_DATA.getInstanceEntranceCountByWorldId(worldId)); // Max Entry's
			writeD(player.getPortalCooldownList().getPortalCooldownItem(worldId) != null ? player.getPortalCooldownList().getPortalCooldownItem(worldId).getEntryCount() * -1 : 0); // Used Entry's
																																													// (negative -)
			writeD(0); // 4.9
			writeD(0); // 4.9
			writeD(0); // Unk 5.1
			writeD(0); // Unk 6.x
			writeC(1); // activated
		}
		writeS(player.getName());
	}
}
 
Example 20
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void load(XMLObjectReader reader) throws XMLStreamException
    {
    	try {
            Integer vali = reader.read(CONNECT_DELAY_PROP, Integer.class);
            if (vali != null)
                this.connectDelay = vali;
            // this.workerThreads = reader.read(WORKER_THREADS_PROP, Integer.class);
            // this.singleThread = reader.read(SINGLE_THREAD_PROP, Boolean.class);
            vali = reader.read(WORKER_THREADS_PROP, Integer.class);
            Boolean valb = reader.read(SINGLE_THREAD_PROP, Boolean.class);
        } catch (java.lang.NullPointerException npe) {
            // ignore.
            // For backward compatibility we can ignore if these values are not defined
        }

        Double valTH1 = reader.read(CONG_CONTROL_DELAY_THRESHOLD_1, Double.class);
        Double valTH2 = reader.read(CONG_CONTROL_DELAY_THRESHOLD_2, Double.class);
        Double valTH3 = reader.read(CONG_CONTROL_DELAY_THRESHOLD_3, Double.class);
        Double valTB1 = reader.read(CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_1, Double.class);
        Double valTB2 = reader.read(CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_2, Double.class);
        Double valTB3 = reader.read(CONG_CONTROL_BACK_TO_NORMAL_DELAY_THRESHOLD_3, Double.class);
        if (valTH1 != null && valTH2 != null && valTH3 != null && valTB1 != null && valTB2 != null && valTB3 != null) {
            this.congControl_DelayThreshold = new double[3];
            this.congControl_DelayThreshold[0] = valTH1;
            this.congControl_DelayThreshold[1] = valTH2;
            this.congControl_DelayThreshold[2] = valTH3;
            this.congControl_BackToNormalDelayThreshold = new double[3];
            this.congControl_BackToNormalDelayThreshold[0] = valTB1;
            this.congControl_BackToNormalDelayThreshold[1] = valTB2;
            this.congControl_BackToNormalDelayThreshold[2] = valTB3;
        }

        // TODO: add storing of parameters
//        Boolean valB = reader.read(OPTION_SCTP_DISABLE_FRAGMENTS, Boolean.class);
//        if (valB != null)
//            this.optionSctpDisableFragments = valB;
//        Integer valI = reader.read(OPTION_SCTP_FRAGMENT_INTERLEAVE, Integer.class);
//        if (valI != null)
//            this.optionSctpFragmentInterleave = valI;
//        Integer valI_In = reader.read(OPTION_SCTP_INIT_MAXSTREAMS_IN, Integer.class);
//        Integer valI_Out = reader.read(OPTION_SCTP_INIT_MAXSTREAMS_OUT, Integer.class);
//        if (valI_In != null && valI_Out != null) {
//            this.optionSctpInitMaxstreams = SctpStandardSocketOptions.InitMaxStreams.create(valI_In, valI_Out);
//        }
//        valB = reader.read(OPTION_SCTP_NODELAY, Boolean.class);
//        if (valB != null)
//            this.optionSctpNodelay = valB;
//        valI = reader.read(OPTION_SO_SNDBUF, Integer.class);
//        if (valI != null)
//            this.optionSoSndbuf = valI;
//        valI = reader.read(OPTION_SO_RCVBUF, Integer.class);
//        if (valI != null)
//            this.optionSoRcvbuf = valI;
//        valI = reader.read(OPTION_SO_LINGER, Integer.class);
//        if (valI != null)
//            this.optionSoLinger = valI;

        this.servers = reader.read(SERVERS, FastList.class);

        for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
            Server serverTemp = n.getValue();
            ((NettyServerImpl) serverTemp).setManagement(this);
            if (serverTemp.isStarted()) {
                try {
                    ((NettyServerImpl) serverTemp).start();
                } catch (Exception e) {
                    logger.error(String.format("Error while initiating Server=%s", serverTemp.getName()), e);
                }
            }
        }

        this.associations = reader.read(ASSOCIATIONS, NettyAssociationMap.class);
        for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n
                .getNext()) != end;) {
            NettyAssociationImpl associationTemp = (NettyAssociationImpl) n.getValue();
            associationTemp.setManagement(this);
        }
    }