<commit_before>package com.ociweb.iot.hardware;

import java.util.Arrays;

import com.ociweb.pronghorn.iot.AbstractTrafficOrderedStage;
import com.ociweb.pronghorn.iot.schema.MessagePubSub;
import com.ociweb.pronghorn.iot.schema.MessageSubscription;
import com.ociweb.pronghorn.iot.schema.TrafficAckSchema;
import com.ociweb.pronghorn.iot.schema.TrafficReleaseSchema;
import com.ociweb.pronghorn.pipe.Pipe;
import com.ociweb.pronghorn.pipe.PipeReader;
import com.ociweb.pronghorn.pipe.PipeWriter;
import com.ociweb.pronghorn.pipe.util.hash.IntHashTable;
import com.ociweb.pronghorn.stage.scheduling.GraphManager;
import com.ociweb.pronghorn.util.TrieParser;
import com.ociweb.pronghorn.util.TrieParserReader;

public class MessagePubSubStage extends AbstractTrafficOrderedStage {

    private final Pipe<MessagePubSub>[] incomingSubsAndPubsPipe;
    private final Pipe<MessageSubscription>[] outgoingMessagePipes;
    
    private static final int estimatedTopicLength = 100;
    private static final int maxLists = 10; //TODO: make this grow as needed based on growing count of subscriptions.
    private final int subscriberListSize;
    private short[] subscriberLists;
    private int totalSubscriberLists;
    
    private TrieParser trie; 
    private TrieParserReader trieReader;
    
    private IntHashTable subscriptionPipeLookup;
    
    private int[] pendingPublish;
    
    enum PubType {
    	Message, State;
    }
    
    private PubType pendingDeliveryType;
        
    private int pendingPublishCount;
    private int pendingReleaseCountIdx;

    private int currentState;
    private int newState;
    
    public MessagePubSubStage(GraphManager gm, IntHashTable subscriptionPipeLookup, Hardware hardware, Pipe<MessagePubSub>[] incomingSubsAndPubsPipe,
                              Pipe<TrafficReleaseSchema>[] goPipe,
                              Pipe<TrafficAckSchema>[] ackPipe, 
                              Pipe<MessageSubscription>[] outgoingMessagePipes) {
       super(gm, hardware, incomingSubsAndPubsPipe, goPipe, ackPipe, outgoingMessagePipes);

       this.incomingSubsAndPubsPipe = incomingSubsAndPubsPipe;
       this.outgoingMessagePipes = outgoingMessagePipes;
       
       assert(goPipe.length == ackPipe.length) : "should be one ack pipe for every go pipe";
       
       this.subscriberListSize = outgoingMessagePipes.length;//can never hava more subscribers than ALL
       this.totalSubscriberLists = 0;
       this.subscriptionPipeLookup = subscriptionPipeLookup;

       this.currentState = hardware.beginningState.ordinal();
       
    }
    
    @Override
    public void startup() {
        super.startup();<commit_msg>null pointer error when no state is used.<commit_after>package com.ociweb.iot.hardware;

import java.util.Arrays;

import com.ociweb.pronghorn.iot.AbstractTrafficOrderedStage;
import com.ociweb.pronghorn.iot.schema.MessagePubSub;
import com.ociweb.pronghorn.iot.schema.MessageSubscription;
import com.ociweb.pronghorn.iot.schema.TrafficAckSchema;
import com.ociweb.pronghorn.iot.schema.TrafficReleaseSchema;
import com.ociweb.pronghorn.pipe.Pipe;
import com.ociweb.pronghorn.pipe.PipeReader;
import com.ociweb.pronghorn.pipe.PipeWriter;
import com.ociweb.pronghorn.pipe.util.hash.IntHashTable;
import com.ociweb.pronghorn.stage.scheduling.GraphManager;
import com.ociweb.pronghorn.util.TrieParser;
import com.ociweb.pronghorn.util.TrieParserReader;

public class MessagePubSubStage extends AbstractTrafficOrderedStage {

    private final Pipe<MessagePubSub>[] incomingSubsAndPubsPipe;
    private final Pipe<MessageSubscription>[] outgoingMessagePipes;
    
    private static final int estimatedTopicLength = 100;
    private static final int maxLists = 10; //TODO: make this grow as needed based on growing count of subscriptions.
    private final int subscriberListSize;
    private short[] subscriberLists;
    private int totalSubscriberLists;
    
    private TrieParser trie; 
    private TrieParserReader trieReader;
    
    private IntHashTable subscriptionPipeLookup;
    
    private int[] pendingPublish;
    
    enum PubType {
    	Message, State;
    }
    
    private PubType pendingDeliveryType;
        
    private int pendingPublishCount;
    private int pendingReleaseCountIdx;

    private int currentState;
    private int newState;
    
    public MessagePubSubStage(GraphManager gm, IntHashTable subscriptionPipeLookup, Hardware hardware, Pipe<MessagePubSub>[] incomingSubsAndPubsPipe,
                              Pipe<TrafficReleaseSchema>[] goPipe,
                              Pipe<TrafficAckSchema>[] ackPipe, 
                              Pipe<MessageSubscription>[] outgoingMessagePipes) {
       super(gm, hardware, incomingSubsAndPubsPipe, goPipe, ackPipe, outgoingMessagePipes);

       this.incomingSubsAndPubsPipe = incomingSubsAndPubsPipe;
       this.outgoingMessagePipes = outgoingMessagePipes;
       
       assert(goPipe.length == ackPipe.length) : "should be one ack pipe for every go pipe";
       
       this.subscriberListSize = outgoingMessagePipes.length;//can never hava more subscribers than ALL
       this.totalSubscriberLists = 0;
       this.subscriptionPipeLookup = subscriptionPipeLookup;

       this.currentState = null==hardware.beginningState ? -1 :hardware.beginningState.ordinal();
       
    }
    
    @Override
    public void startup() {
        super.startup();
{'fraction_non_alphanumeric': 0.07261640798226164, 'fraction_numerical': 0.002402069475240207, 'mean_word_length': 3.595076400679117, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2559469', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1572, 'n_words': 330}