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

co.edu.uniquindio.utils.communication.transfer.network.CommunicationManagerTCP Maven / Gradle / Ivy

/*
 *  Communication project implement communication point to point and multicast
 *  Copyright (C) 2010  Daniel Pelaez, Daniel Lopez, Hector Hurtado
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see .
 */

package co.edu.uniquindio.utils.communication.transfer.network;

import co.edu.uniquindio.utils.communication.transfer.Communicator;
import org.apache.log4j.Logger;

/**
 * The CommunicationManagerTCP class is an
 * CommunicationManagerNetworkLAN. Implemented the creation of
 * transfer object and unicast manager. Required params: PORT_TCP_RESOURCE and
 * PORT_TCP
 * 
 * @author Daniel Pelaez
 * @author Hector Hurtado
 * @author Daniel Lopez
 * @version 1.0, 17/06/2010
 * @since 1.0
 * 
 */
public class CommunicationManagerTCP extends CommunicationManagerNetworkLAN {
	public CommunicationManagerTCP(MessageSerialization messageSerialization) {
		super(messageSerialization);
	}

    /**
	 * The CommunicationManagerTCPProperties enum contains params
	 * required for communication
	 * 
	 * @author dpelaez
	 * 
	 */
	public enum CommunicationManagerTCPProperties {
		PORT_TCP_RESOURCE, PORT_TCP
	}

	/**
	 * Logger
	 */
	private static final Logger logger = Logger
			.getLogger(CommunicationManagerTCP.class);

	/**
	 * Creates a BytesTransferManagerTCP instance. Required param in
	 * CommunicationProperties called PORT_TCP_RESOURCE
	 */
	protected Communicator createUnicastBigManager() {
		int portTcp;
		if (communicationProperties
				.containsKey(CommunicationManagerTCPProperties.PORT_TCP_RESOURCE
						.name())) {
			portTcp = Integer.parseInt(communicationProperties
					.get(CommunicationManagerTCPProperties.PORT_TCP_RESOURCE
							.name()));
		} else {
			IllegalArgumentException illegalArgumentException = new IllegalArgumentException(
					"Property PORT_TCP_RESOURCE not found");

			logger.error("Property PORT_TCP_RESOURCE not found",
					illegalArgumentException);

			throw illegalArgumentException;
		}
		unicastBigManager = new UnicastBigManagerTCP(portTcp, messageSerialization);

		return unicastBigManager;
	}

	/**
	 * Creates a UnicastManagerTCP instance. Required param in
	 * CommunicationProperties called PORT_TCP.
	 */
	protected Communicator createUnicastManager() {
		int portTcp;
		if (communicationProperties
				.containsKey(CommunicationManagerTCPProperties.PORT_TCP.name())) {
			portTcp = Integer.parseInt(communicationProperties
					.get(CommunicationManagerTCPProperties.PORT_TCP.name()));
		} else {
			IllegalArgumentException illegalArgumentException = new IllegalArgumentException(
					"Property PORT_TCP not found");

			logger.error("Property PORT_TCP not found",
					illegalArgumentException);

			throw illegalArgumentException;
		}
		unicastManager = new UnicastManagerTCP(portTcp, messageSerialization);

		return unicastManager;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy