<commit_before>package smartsockets.virtual;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.BindException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.log4j.Logger;

import smartsockets.Properties;
import smartsockets.direct.SocketAddressSet;
import smartsockets.discovery.Discovery;
import smartsockets.hub.servicelink.ServiceLink;
import smartsockets.util.TypedProperties;
import smartsockets.virtual.modules.ConnectModule;

/**
 * This class implements a 'virtual' socket factory.
 *  
 * @author <NAME>
 * @version 1.0 Jan 30, 2006
 * @since 1.0
 * 
 */
public class VirtualSocketFactory {
    
    private static final HashMap factories = new HashMap();
        
    private final HashMap connectionSetupCache = new HashMap(); 
    
    protected static Logger logger =         
        ibis.util.GetLogger.getLogger("smartsockets.virtual.misc");
            
    private final ArrayList modules = new ArrayList();

    private final TypedProperties properties;
    
    private final int DEFAULT_BACKLOG;     
    private final int DEFAULT_TIMEOUT;         
  //  private final int DISCOVERY_PORT;
        
    private HashMap serverSockets = new HashMap();        
    private int nextPort = 3000;    
    
    private SocketAddressSet myAddresses;      
    private SocketAddressSet proxyAddress;    
    private String cluster;
    
    private ServiceLink serviceLink;
    
    private ClusterDefinition defaultOrder;
    private HashMap clusterSpecificOrder;
            
    private class ClusterDefinition {         
        final String name;        
        final ConnectModule [] order;
        
        ClusterDefinition(String name, ConnectModule [] order) {
            this.name = name;
            this.order = order;
        }
    }
    
    private VirtualSocketFactory(TypedProperties p) throws Exception {
                
        logger.info("Creating VirtualSocketFactory");    
        
        properties = p;
        
        DEFAULT_BACKLOG = p.getIntProperty(Properties.BACKLOG);
        DEFAULT_TIMEOUT = p.getIntProperty(Properties.TIMEOUT);
       // DISCOVERY_PORT = 
    
        // NOTE: order is VERY important here!
        loadModules();        
        loadClusterDefinitions();                        
        createServiceLink();
        passServiceLinkToModules();        
        
        if (modules.size() == 0) { 
            logger.warn("Failed to load any modules!");
            throw new Exception("Failed to load any modules!");
        }       
    } 
    
    private void loadClusterDefinitions() { 
        
        cluster = properties.getProperty(Properties.CLUSTER_MEMBER, null);               
        
        String [] clusters = 
            properties.getStringList(Properties.CLUSTER_DEFINE, ",", null);
               
        if (clusters == null && cluster != null) { 
            logger.warn("No virtual cluster definitions found!");
            return;
        }
        <commit_msg>Fixed nullpointer exception trigger whn the cluster definitions  are a bit strange.<commit_after>package smartsockets.virtual;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.BindException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.log4j.Logger;

import smartsockets.Properties;
import smartsockets.direct.SocketAddressSet;
import smartsockets.discovery.Discovery;
import smartsockets.hub.servicelink.ServiceLink;
import smartsockets.util.TypedProperties;
import smartsockets.virtual.modules.ConnectModule;

/**
 * This class implements a 'virtual' socket factory.
 *  
 * @author <NAME>
 * @version 1.0 Jan 30, 2006
 * @since 1.0
 * 
 */
public class VirtualSocketFactory {
    
    private static final HashMap factories = new HashMap();
        
    private final HashMap connectionSetupCache = new HashMap(); 
    
    protected static Logger logger =         
        ibis.util.GetLogger.getLogger("smartsockets.virtual.misc");
            
    private final ArrayList modules = new ArrayList();

    private final TypedProperties properties;
    
    private final int DEFAULT_BACKLOG;     
    private final int DEFAULT_TIMEOUT;         
  //  private final int DISCOVERY_PORT;
        
    private HashMap serverSockets = new HashMap();        
    private int nextPort = 3000;    
    
    private SocketAddressSet myAddresses;      
    private SocketAddressSet proxyAddress;    
    private String cluster;
    
    private ServiceLink serviceLink;
    
    private ClusterDefinition defaultOrder;
    private HashMap clusterSpecificOrder;
            
    private class ClusterDefinition {         
        final String name;        
        final ConnectModule [] order;
        
        ClusterDefinition(String name, ConnectModule [] order) {
            this.name = name;
            this.order = order;
        }
    }
    
    private VirtualSocketFactory(TypedProperties p) throws Exception {
                
        logger.info("Creating VirtualSocketFactory");    
        
        properties = p;
        
        DEFAULT_BACKLOG = p.getIntProperty(Properties.BACKLOG);
        DEFAULT_TIMEOUT = p.getIntProperty(Properties.TIMEOUT);
       // DISCOVERY_PORT = 
    
        // NOTE: order is VERY important here!
        loadModules();        
        loadClusterDefinitions();                        
        createServiceLink();
        passServiceLinkToModules();        
        
        if (modules.size() == 0) { 
            logger.warn("Failed to load any modules!");
            throw new Exception("Failed to load any modules!");
        }       
    } 
    
    private void loadClusterDefinitions() { 
        
        cluster = properties.getProperty(Properties.CLUSTER_MEMBER, null);               
        
        if (cluster == null) {
            // We don't belong to any cluster, so it's no use parsing the rest 
            // of the cluster definitions...
            return;
        }
        
        String [] clusters = 
            properties.getStringList(Properties.CLUSTER_DEFINE, ",", null);
               
        if (clusters == null && cluster != null) { 
            logger.warn("No virtual cluster definitions found!");
            return;
        }
        
{'fraction_non_alphanumeric': 0.07800030115946394, 'fraction_numerical': 0.004818551422978467, 'mean_word_length': 2.1978815599422243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6027434', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1631, 'n_words': 434}