001    /*
002     * Copyright (c) 1998-2013 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    package com.chemaxon.overlap.concurrent;
011    
012    import java.util.concurrent.Future;
013    
014    /**
015     * MBean for managing batched paged processor.
016     *
017     * @author Gabor Imre
018     */
019    // TODO: Cancel starving (avoid race condition)
020    // TODO: Queue status
021    public interface BppManagerMBean {
022    
023        /**
024         * Current results queue size limit.
025         *
026         * @return Current queue size limit.
027         */
028        int getMaxQueueSize();
029    
030        /**
031         * Set new max queue size parameter.
032         *
033         * @param queueSize New queue size
034         */
035        void setMaxQueueSize(int queueSize);
036    
037        /**
038         * Current size of the results queue.
039         *
040         * @return Current results queue size
041         */
042        int getQueueSize();
043    
044        /**
045         * Non finished items in the queue.
046         *
047         * @return Non finished items in the queue
048         */
049        int getNonFinishedCount();
050    
051        /**
052         * Current page size.
053         *
054         * <p>
055         * Number of input items bundled into one page which is one execution unit.</p>
056         *
057         * @return current page size
058         */
059        int getPageSize();
060    
061        /**
062         * Set new page size.
063         *
064         * <p>
065         * Note that new page size will be effective upon next enqueue operation. Pages in the results queue are not
066         * affected.</p>
067         *
068         * @param size New page size.
069         */
070        void setPageSize(int size);
071    
072        /**
073         * Number of individual inputs read from the input source.
074         *
075         * <p>
076         * This is the sum of ready and reported, ready and not reported and enqueued inputs.</p>
077         *
078         * @return Read input count
079         */
080        long getInputCount();
081    
082        /**
083         * Number of reported results.
084         *
085         * @return Number of reported results
086         */
087        long getOutputCount();
088    
089        /**
090         * Inputs represented by the first enqueued page in <code>String</code> format.
091         *
092         * <p>
093         * More precisely the page in the head of the results queue. This page might be ready and waiting for reporting, in
094         * progress or wait for execution.</p>
095         *
096         * @return Inputs represented by the first page
097         */
098        String[] getFirstPageSources();
099    
100        /**
101         * Kill first page only if all other pages are ready.
102         *
103         * <p>
104         * All the inputs will be reported as failures. If the first page was not blocking an exception is thrown.</p>
105         *
106         * @throws IllegalStateException If the first page is done (see {@link Future#isDone()} or at least one page in the
107         * queue is not done.
108         */
109        void killFirstPageIfBlocking();
110    
111        /**
112         * Kill first page unconditionally.
113         *
114         * <p>
115         * If the first page is ready and waiting for reporting the results will be overriden with failure.</p>
116         */
117        void killFirstPage();
118    
119        /**
120         * Kill first page and freeze worker.
121         */
122        void killAllAndFreeze();
123    
124        /**
125         * Check frozen status.
126         *
127         * @return true if executor is frozen
128         */
129        boolean isFrozen();
130    
131        /**
132         * Freeze worker.
133         *
134         * <p>
135         * Note that frozen status implies that worker will prefer blocking when queue size limits otherwise would allow new
136         * task submission. New task submission is however possibly accepted in frozen status.</p>
137         *
138         * <p>
139         * If the worker is already frozen do nothing.</p>
140         */
141        void freeze();
142    
143        /**
144         * Unfreeze worker.
145         *
146         * <p>
147         * If the worker is not frozen do nothing.</p>
148         */
149        void unfreeze();
150    
151    }