Java Code Examples for javolution.util.FastList#Node

The following examples show how to use javolution.util.FastList#Node . 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: WorldBuffService.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void onReturnHome(Npc npc) {
	FastList<WorldBuffTemplate> buff = worldBuff.get(npc.getWorldId());
	if (buff == null) {
		return;
	}
	for (FastList.Node<WorldBuffTemplate> n = buff.head(), end = buff.tail(); (n = n.getNext()) != end;) {
		WorldBuffTemplate bf = n.getValue();
		if (bf.getType().equals(WorldBuffType.PC)) {
			continue;
		}
		for (FastList.Node<TribeClass> t = bf.getTribe().head(), endt = bf.getTribe().tail(); (t = t.getNext()) != endt;) {
			if (npc.getTribe().equals(t.getValue())) {
				buff(bf, npc);
				break;
			}
		}
		if (!bf.getNpcIds().isEmpty() && bf.getNpcIds().contains(npc.getNpcId())) {
			buff(bf, npc);
		}
	}
}
 
Example 2
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void stopServer(String serverName) throws Exception {
    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

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

    FastList<Server> tempServers = servers;
    for (FastList.Node<Server> n = tempServers.head(), end = tempServers.tail(); (n = n.getNext()) != end;) {
        Server serverTemp = n.getValue();

        if (serverName.equals(serverTemp.getName())) {
            ((NettyServerImpl) serverTemp).stop();
            this.store();
            return;
        }
    }

    throw new Exception(String.format("No Server found with name=%s", serverName));

}
 
Example 3
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 6 votes vote down vote up
public void startServer(String serverName) throws Exception {

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

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

		FastList<Server> tempServers = servers;
		for (FastList.Node<Server> n = tempServers.head(), end = tempServers.tail(); (n = n.getNext()) != end;) {
			Server serverTemp = n.getValue();

			if (serverName.equals(serverTemp.getName())) {
				if (serverTemp.isStarted()) {
					throw new Exception(String.format("Server=%s is already started", serverName));
				}
				((ServerImpl) serverTemp).start();
				this.store();
				return;
			}
		}

		throw new Exception(String.format("No Server foubd with name=%s", serverName));
	}
 
Example 4
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 6 votes vote down vote up
public void stopServer(String serverName) throws Exception {

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

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

		FastList<Server> tempServers = servers;
		for (FastList.Node<Server> n = tempServers.head(), end = tempServers.tail(); (n = n.getNext()) != end;) {
			Server serverTemp = n.getValue();

			if (serverName.equals(serverTemp.getName())) {
				((ServerImpl) serverTemp).stop();
				this.store();
				return;
			}
		}

		throw new Exception(String.format("No Server found with name=%s", serverName));
	}
 
Example 5
Source File: RunatoriumPacketsHandler.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void ClearTasks() {
	isInstanceDestroyed = true;

	for (FastList.Node<Future<?>> n = idgelTask.head(), end = idgelTask.tail(); (n = n.getNext()) != end;) {
		if (n.getValue() != null) {
			n.getValue().cancel(true);
		}
	}
}
 
Example 6
Source File: WorldBuffService.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void onEnterWorld(Player player) {
	if (player.getWorldBuffList() == null) {
		onAfterSpawn(player);
		return;
	}
	FastList<WorldBuff> buff = player.getWorldBuffList();
	for (FastList.Node<WorldBuff> n = buff.head(), end = buff.tail(); (n = n.getNext()) != end;) {
		if (player.getWorldId() != n.getValue().getWorldId()) {
			for (FastList.Node<Integer> s = n.getValue().getSkillIds().head(), ends = n.getValue().getSkillIds().tail(); (s = s.getNext()) != ends;) {
				player.getEffectController().removeEffect(s.getValue());
			}
			player.getWorldBuffList().remove(n.getValue());
		}
	}
}
 
Example 7
Source File: WorldBuffService.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void onLogOut(Player player) {
	if (player.getWorldBuffList() == null) {
		return;
	}
	FastList<WorldBuff> buff = player.getWorldBuffList();
	for (FastList.Node<WorldBuff> n = buff.head(), end = buff.tail(); (n = n.getNext()) != end;) {
		if (player.getWorldId() != n.getValue().getWorldId()) {
			for (FastList.Node<Integer> s = n.getValue().getSkillIds().head(), ends = n.getValue().getSkillIds().tail(); (s = s.getNext()) != ends;) {
				player.getEffectController().removeEffect(s.getValue());
			}
			player.getWorldBuffList().remove(n.getValue());
		}
	}
}
 
Example 8
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void startServer(String serverName) throws Exception {
    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

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

    FastList<Server> tempServers = servers;
    for (FastList.Node<Server> n = tempServers.head(), end = tempServers.tail(); (n = n.getNext()) != end;) {
        Server serverTemp = n.getValue();

        if (serverName.equals(serverTemp.getName())) {
            if (serverTemp.isStarted()) {
                throw new Exception(String.format("Server=%s is already started", serverName));
            }
            ((NettyServerImpl) serverTemp).start();
            this.store();
            return;
        }
    }

    throw new Exception(String.format("No Server foubd with name=%s", serverName));

}
 
Example 9
Source File: NettyServerImpl.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String toString() {

    StringBuilder sb = new StringBuilder();

    sb.append("Server [name=").append(this.name).append(", started=").append(this.started).append(", hostAddress=").append(this.hostAddress)
            .append(", hostPort=").append(hostport).append(", ipChannelType=").append(ipChannelType).append(", acceptAnonymousConnections=")
            .append(this.acceptAnonymousConnections).append(", maxConcurrentConnectionsCount=").append(this.maxConcurrentConnectionsCount)
            .append(", associations(anonymous does not included)=[");

    for (FastList.Node<String> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
        sb.append(n.getValue());
        sb.append(", ");
    }

    sb.append("], extraHostAddress=[");

    if (this.extraHostAddresses != null) {
        for (int i = 0; i < this.extraHostAddresses.length; i++) {
            String extraHostAddress = this.extraHostAddresses[i];
            sb.append(extraHostAddress);
            sb.append(", ");
        }
    }

    sb.append("]]");

    return sb.toString();
}
 
Example 10
Source File: ServerImpl.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String toString() {

	StringBuilder sb = new StringBuilder();

       sb.append("Server [name=").append(this.name).append(", started=").append(this.started).append(", hostAddress=").append(this.hostAddress)
               .append(", hostPort=").append(hostport).append(", ipChannelType=").append(ipChannelType).append(", acceptAnonymousConnections=")
               .append(this.acceptAnonymousConnections).append(", maxConcurrentConnectionsCount=").append(this.maxConcurrentConnectionsCount)
               .append(", associations(anonymous does not included)=[");

	for (FastList.Node<String> n = this.associations.head(), end = this.associations.tail(); (n = n.getNext()) != end;) {
		sb.append(n.getValue());
		sb.append(", ");
	}

	sb.append("], extraHostAddress=[");

	if (this.extraHostAddresses != null) {
		for (int i = 0; i < this.extraHostAddresses.length; i++) {
			String extraHostAddress = this.extraHostAddresses[i];
			sb.append(extraHostAddress);
			sb.append(", ");
		}
	}

	sb.append("]]");

	return sb.toString();
}
 
Example 11
Source File: NettyServerImpl.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void stop() throws Exception {
    FastList<String> tempAssociations = associations;
    for (FastList.Node<String> n = tempAssociations.head(), end = tempAssociations.tail(); (n = n.getNext()) != end;) {
        String assocName = n.getValue();
        Association associationTemp = this.management.getAssociation(assocName);
        if (associationTemp.isStarted()) {
            throw new Exception(String.format("Stop all the associations first. Association=%s is still started",
                    associationTemp.getName()));
        }
    }

    synchronized (this.anonymAssociations) {
        // stopping all anonymous associations
        for (Association ass : this.anonymAssociations) {
            ass.stopAnonymousAssociation();
        }
        this.anonymAssociations.clear();
    }

    this.started = false;

    if (logger.isInfoEnabled()) {
        logger.info(String.format("Stoped Server=%s", this.name));
    }

    // Stop underlying channel and wait till its done
    if (this.getIpChannel() != null) {
        try {
            this.getIpChannel().close().sync();
        } catch (Exception e) {
            logger.warn(String.format("Error while stopping the Server=%s", this.name), e);
        }
    }
}
 
Example 12
Source File: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void removeAssociation(String assocName) throws Exception {
    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

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

    synchronized (this) {
        Association association = this.associations.get(assocName);

        if (association == null) {
            throw new Exception(String.format("No Association found for name=%s", assocName));
        }

        if (association.isStarted()) {
            throw new Exception(String.format("Association name=%s is started. Stop before removing", assocName));
        }

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

        if (((NettyAssociationImpl) association).getAssociationType() == AssociationType.SERVER) {
            for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
                Server serverTemp = n.getValue();
                if (serverTemp.getName().equals(association.getServerName())) {
                    FastList<String> newAssociations2 = new FastList<String>();
                    newAssociations2.addAll(((NettyServerImpl) serverTemp).associations);
                    newAssociations2.remove(assocName);
                    ((NettyServerImpl) serverTemp).associations = newAssociations2;
                    break;
                }
            }
        }

        this.store();

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

}
 
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: NettySctpManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Server addServer(String serverName, String hostAddress, int port, IpChannelType ipChannelType,
        boolean acceptAnonymousConnections, int maxConcurrentConnectionsCount, String[] extraHostAddresses)
        throws Exception {
    if (!this.started) {
        throw new Exception(String.format("Management=%s not started", this.name));
    }

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

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

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

    synchronized (this) {
        for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
            Server serverTemp = n.getValue();
            if (serverName.equals(serverTemp.getName())) {
                throw new Exception(String.format("Server name=%s already exist", serverName));
            }

            if (hostAddress.equals(serverTemp.getHostAddress()) && port == serverTemp.getHostport()) {
                throw new Exception(String.format("Server name=%s is already bound to %s:%d", serverTemp.getName(),
                        serverTemp.getHostAddress(), serverTemp.getHostport()));
            }
        }

        NettyServerImpl server = new NettyServerImpl(serverName, hostAddress, port, ipChannelType,
                acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses);
        server.setManagement(this);

        FastList<Server> newServers = new FastList<Server>();
        newServers.addAll(this.servers);
        newServers.add(server);
        this.servers = newServers;
        // this.servers.add(server);

        this.store();

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

        if (logger.isInfoEnabled()) {
            logger.info(String.format("Created Server=%s", server.getName()));
        }

        return server;
    }
}
 
Example 15
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);
        }
    }
 
Example 16
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
public void removeAssociation(String assocName) throws Exception {
	if (!this.started) {
		throw new Exception(String.format("Management=%s not started", this.name));
	}

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

	synchronized (this) {
		Association association = this.associations.get(assocName);

		if (association == null) {
			throw new Exception(String.format("No Association found for name=%s", assocName));
		}

		if (association.isStarted()) {
			throw new Exception(String.format("Association name=%s is started. Stop before removing", assocName));
		}

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

		if (((AssociationImpl) association).getAssociationType() == AssociationType.SERVER) {
			for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
				Server serverTemp = n.getValue();
				if (serverTemp.getName().equals(association.getServerName())) {
					FastList<String> newAssociations2 = new FastList<String>();
					newAssociations2.addAll(((ServerImpl) serverTemp).associations);
					newAssociations2.remove(assocName);
					((ServerImpl) serverTemp).associations = newAssociations2;
					// ((ServerImpl)
					// serverTemp).associations.remove(assocName);

					break;
				}
			}
		}

		this.store();

		for (ManagementEventListener lstr : managementEventListeners) {
			try {
				lstr.onAssociationRemoved(association);
			} catch (Throwable ee) {
				logger.error("Exception while invoking onAssociationRemoved", ee);
			}
		}
	}
}
 
Example 17
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 18
Source File: ManagementImpl.java    From sctp with GNU Affero General Public License v3.0 4 votes vote down vote up
public ServerImpl addServer(String serverName, String hostAddress, int port, IpChannelType ipChannelType, boolean acceptAnonymousConnections,
		int maxConcurrentConnectionsCount, String[] extraHostAddresses) throws Exception {

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

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

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

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

	synchronized (this) {
		for (FastList.Node<Server> n = this.servers.head(), end = this.servers.tail(); (n = n.getNext()) != end;) {
			Server serverTemp = n.getValue();
			if (serverName.equals(serverTemp.getName())) {
				throw new Exception(String.format("Server name=%s already exist", serverName));
			}

			if (hostAddress.equals(serverTemp.getHostAddress()) && port == serverTemp.getHostport()) {
				throw new Exception(String.format("Server name=%s is already bound to %s:%d", serverTemp.getName(), serverTemp.getHostAddress(),
						serverTemp.getHostport()));
			}
		}

		ServerImpl server = new ServerImpl(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount,
				extraHostAddresses);
		server.setManagement(this);

		FastList<Server> newServers = new FastList<Server>();
		newServers.addAll(this.servers);
		newServers.add(server);
		this.servers = newServers;
		// this.servers.add(server);

		this.store();

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

		if (logger.isInfoEnabled()) {
			logger.info(String.format("Created Server=%s", server.getName()));
		}

		return server;
	}
}
 
Example 19
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 20
Source File: WorldBuffService.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
public void onAfterSpawn(Creature creature) {
	FastList<WorldBuffTemplate> buff = worldBuff.get(creature.getWorldId());
	if (buff == null) {
		return;
	}

	for (FastList.Node<WorldBuffTemplate> n = buff.head(), end = buff.tail(); (n = n.getNext()) != end;) {
		WorldBuffTemplate bf = n.getValue();
		if (creature instanceof Player) {
			Player player = (Player) creature;
			if (bf.getType().equals(WorldBuffType.NPC)) {
				continue;
			}
			if (player.getWorldBuffList() != null) {
				FastList<WorldBuff> buffList = player.getWorldBuffList();
				for (FastList.Node<WorldBuff> b = buffList.head(), endb = buffList.tail(); (b = b.getNext()) != endb;) {
					if (player.getWorldId() == b.getValue().getWorldId()) {
						buff(bf, creature);
						break;
					}
				}
			}
			else {
				player.addWorldBuff(new WorldBuff(bf.getSkillIds(), player.getWorldId()));
				buff(bf, creature);
			}
		}
		if (creature instanceof Npc) {
			Npc npc = (Npc) creature;
			if (bf.getType().equals(WorldBuffType.PC)) {
				continue;
			}
			for (FastList.Node<TribeClass> t = bf.getTribe().head(), endt = bf.getTribe().tail(); (t = t.getNext()) != endt;) {
				if (npc.getTribe().equals(t.getValue())) {
					buff(bf, npc);
					break;
				}
			}
			if (!bf.getNpcIds().isEmpty() && bf.getNpcIds().contains(npc.getNpcId())) {
				buff(bf, npc);
			}
		}
	}
}