<commit_before>/**
 * For copyright information see the LICENSE document.
 */

package realityshard.container;

import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import realityshard.container.events.Event;
import realityshard.container.events.GameAppCreatedEvent;
import realityshard.container.events.GameAppUnloadedEvent;
import realityshard.container.events.NetworkClientConnectedEvent;
import realityshard.container.gameapp.GameAppContext;
import realityshard.container.gameapp.GameAppManager;


/**
 * Encapsulates all gameapp contexts of a certain kind.
 * 
 * If we got messages from a new client, this context will distribute them
 * to the other contexts.
 * 
 * Note that we only want different game app context instances.
 *
 * @author _rusty
 */
class MetaGameAppContext extends GameAppContext.Default
{

    private final static Logger LOGGER = LoggerFactory.getLogger(MetaGameAppContext.class);

    private Set<GameAppContext> contexts;


    /**
     * Constructor.
     */
    public MetaGameAppContext(String name, GameAppManager manager)
    {
        super(name, manager, null);
        contexts = new HashSet<>();
    }
    
    
    /**
     * Handles the new client event and distributes it to all sub-contexts
     * 
     * @param event 
     */
    @Event.Handler
    public void onNewClient(NetworkClientConnectedEvent event)
    {
        for (GameAppContext context : contexts) 
        {
            context.trigger(event);
        }
    }


    /**
     * Add a new context to the collection of contexts,
     * so the next time a new channel sends a packet, we may also ask that
     * context if it wants to accept the channel.
     * 
     * This will also trigger a GameAppCreatedEvent
     *<commit_msg>meta context now forwards new messages<commit_after>/**
 * For copyright information see the LICENSE document.
 */

package realityshard.container;

import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import realityshard.container.events.Event;
import realityshard.container.events.GameAppCreatedEvent;
import realityshard.container.events.GameAppUnloadedEvent;
import realityshard.container.events.NetworkClientConnectedEvent;
import realityshard.container.gameapp.GameAppContext;
import realityshard.container.gameapp.GameAppManager;
import realityshard.container.network.Message;


/**
 * Encapsulates all gameapp contexts of a certain kind.
 * 
 * If we got messages from a new client, this context will distribute them
 * to the other contexts.
 * 
 * Note that we only want different game app context instances.
 *
 * @author _rusty
 */
class MetaGameAppContext extends GameAppContext.Default
{

    private final static Logger LOGGER = LoggerFactory.getLogger(MetaGameAppContext.class);

    private Set<GameAppContext> contexts;


    /**
     * Constructor.
     */
    public MetaGameAppContext(String name, GameAppManager manager)
    {
        super(name, manager, null);
        contexts = new HashSet<>();
    }
    
    
    /**
     * Handles the new client event and distributes it to all sub-contexts
     * 
     * @param event 
     */
    @Event.Handler
    public void onNewClient(NetworkClientConnectedEvent event)
    {
        for (GameAppContext context : contexts) 
        {
            context.trigger(event);
        }
    }
    
    
    /**
     * Handles the messages from all unconnected clients,
     * and distributes it to all sub-contexts
     * 
     * @param message 
     */
    @Override
    public void handleMessage(Message message)
    {
        for (GameAppContext context : contexts) 
        {
            context.handleMessage(message);
        }
    }


    /**
     * Add a new context to the collection of contexts,
     * so the next time a new channel sends a packet, we may also ask that
     * context if it wants to accept the channel.
     * 
     * This will also trigger a GameAppCreatedEvent
     *
{'fraction_non_alphanumeric': 0.07590511860174781, 'fraction_numerical': 0.0009987515605493133, 'mean_word_length': 2.954590325765054, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6347232', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1076, 'n_words': 338}