<commit_before>/////////////////////////////////////////////////////////////////////////
//
// (c) University of Southampton IT Innovation Centre, 2012
//
// Copyright in this software belongs to University of Southampton
// IT Innovation Centre of Gamma House, Enterprise Road, 
// Chilworth Science Park, Southampton, SO16 7NS, UK.
//
// This software may not be used, sold, licensed, transferred, copied
// or reproduced in whole or in part in any manner or form or in or
// on any media by any person other than in accordance with the terms
// of the Licence Agreement supplied with the software, or otherwise
// without the prior written consent of the copyright owners.
//
// This software is distributed WITHOUT ANY WARRANTY, without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE, except where stated in the Licence Agreement supplied with
// the software.
//
//      Created By :            <NAME>
//      Created Date :          08-Jul-2012
//      Created for Project :   EXPERIMEDIA
//
/////////////////////////////////////////////////////////////////////////

package uk.ac.soton.itinnovation.experimedia.arch.ecc.amqpAPI.impl.amqp;

import java.io.*;
import java.net.*;
import java.util.*;

import com.rabbitmq.client.*;




public class AMQPConnectionFactory
{
  private InetAddress amqpHostIP;
  private Connection  amqpConnection;
  
  private HashSet<AMQPBasicChannel> amqpChannels;
  
  public AMQPConnectionFactory()
  {
    amqpChannels = new HashSet<AMQPBasicChannel>();
  } 
  
  public boolean setAMQPHostIPAddress( String addr )
  {
    boolean ipSuccess = false;
    
    try
    {
      amqpHostIP = InetAddress.getByName( addr );
      ipSuccess = true;
    }
    catch ( UnknownHostException uhe ) { amqpHostIP = null; }
    
    return ipSuccess;
  }
  
  public String getLocalIP()
  {
    String localIPValue = null;
    
    try
    {
      InetAddress localIP = InetAddress.getLocalHost();
      localIPValue = localIP.getHostAddress();
    }
    catch ( UnknownHostException uhe ) {}
    
    return localIPValue;
  }
  
  public void connectToAMQPHost() throws Exception
  {    
    // Safety first
    if ( amqpHostIP == null ) throw new Exception( "AMQP Host IP not correct" );
    if ( amqpConnection != null ) throw new Exception( "Already connected to host" );
    
    ConnectionFactory amqpFactory = new ConnectionFactory();
    amqpFactory.setHost( amqpHostIP.getHostAddress() );
      
    try { amqpConnection = amqpFactory.newConnection(); }
    catch ( IOException ioe )
    { throw new Exception( "Could not create AMQP host connection" ); }
  }
  
  public boolean isConnectionValid()
  { return (amqpConnection != null); }
  
  public void disconnectAMSQPHost()
  {
    // Close known channels
    Iterator<AMQPBasicChannel> channelIt = amqpChannels.iterator();
    while ( channelIt.hasNext() )
    { channelIt.next().close(); }
    
    amqpChannels.clear();
    
    try { if ( amqpConnection != null ) amqpConnection.close(); }
    catch (IOException ioe) {}
  }
  
  public AMQPBasicChannel createNewChannel() throws Exception
  {
    if ( amqpConnection == null ) throw new Exception( "No AMSQP connection available" );
    
    AMQPBasicChannel newChannel = new AMQPBasicChannel( amqpConnection.createChannel() );
    amqpChannels.add( newChannel );
    
    return newChannel;
  }
}<commit_msg>Removed reference control of AMQPBasicChannel from factory.<commit_after>/////////////////////////////////////////////////////////////////////////
//
// (c) University of Southampton IT Innovation Centre, 2012
//
// Copyright in this software belongs to University of Southampton
// IT Innovation Centre of Gamma House, Enterprise Road, 
// Chilworth Science Park, Southampton, SO16 7NS, UK.
//
// This software may not be used, sold, licensed, transferred, copied
// or reproduced in whole or in part in any manner or form or in or
// on any media by any person other than in accordance with the terms
// of the Licence Agreement supplied with the software, or otherwise
// without the prior written consent of the copyright owners.
//
// This software is distributed WITHOUT ANY WARRANTY, without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE, except where stated in the Licence Agreement supplied with
// the software.
//
//      Created By :            <NAME>rowle
//      Created Date :          08-Jul-2012
//      Created for Project :   EXPERIMEDIA
//
/////////////////////////////////////////////////////////////////////////

package uk.ac.soton.itinnovation.experimedia.arch.ecc.amqpAPI.impl.amqp;

import java.io.*;
import java.net.*;

import com.rabbitmq.client.*;




public class AMQPConnectionFactory
{
  private InetAddress amqpHostIP;
  private Connection  amqpConnection;
  
  
  public AMQPConnectionFactory()
  {
  } 
  
  public boolean setAMQPHostIPAddress( String addr )
  {
    boolean ipSuccess = false;
    
    try
    {
      amqpHostIP = InetAddress.getByName( addr );
      ipSuccess = true;
    }
    catch ( UnknownHostException uhe ) { amqpHostIP = null; }
    
    return ipSuccess;
  }
  
  public String getLocalIP()
  {
    String localIPValue = null;
    
    try
    {
      InetAddress localIP = InetAddress.getLocalHost();
      localIPValue = localIP.getHostAddress();
    }
    catch ( UnknownHostException uhe ) {}
    
    return localIPValue;
  }
  
  public void connectToAMQPHost() throws Exception
  {    
    // Safety first
    if ( amqpHostIP == null ) throw new Exception( "AMQP Host IP not correct" );
    if ( amqpConnection != null ) throw new Exception( "Already connected to host" );
    
    ConnectionFactory amqpFactory = new ConnectionFactory();
    amqpFactory.setHost( amqpHostIP.getHostAddress() );
      
    try { amqpConnection = amqpFactory.newConnection(); }
    catch ( IOException ioe )
    { throw new Exception( "Could not create AMQP host connection" ); }
  }
  
  public boolean isConnectionValid()
  { return (amqpConnection != null); }
  
  public AMQPBasicChannel createNewChannel() throws Exception
  {
    if ( amqpConnection == null ) throw new Exception( "No AMSQP connection available" );
    
    return new AMQPBasicChannel( amqpConnection.createChannel() );
  }
}
{'fraction_non_alphanumeric': 0.12905792488860598, 'fraction_numerical': 0.004137492043284532, 'mean_word_length': 2.519036954087346, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1700924', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1675, 'n_words': 564}