001/*******************************************************************************
002The MIT License (MIT)
003
004Copyright (c) 2024 KILLCODING.COM
005
006Permission is hereby granted, free of charge, to any person obtaining a copy
007of this software and associated documentation files (the "Software"), to deal
008in the Software without restriction, including without limitation the rights
009to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010copies of the Software, and to permit persons to whom the Software is
011furnished to do so, subject to the following conditions:
012
013The above copyright notice and this permission notice shall be included in
014all copies or substantial portions of the Software.
015
016THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
022THE SOFTWARE.
023*****************************************************************************/
024package com.killcoding.cache;
025
026import com.killcoding.cache.CacheArray;
027import com.killcoding.log.LoggerFactory;
028import com.killcoding.log.Logger;
029import java.util.List;
030
031/**
032 * This class is used with 'CacheArray'
033 * */
034public class CacheArrayFilter {
035
036        private Long timer = 10L;
037        
038        private Long loopTimer = 10L;
039        
040        private CacheArray cacheArray = null;
041        
042        protected boolean terminated = false;
043        protected boolean forceTerminated = false;
044
045    /**
046     * New a CacheArrayFilter Object
047     * @param timer - Timer,default is 10ms
048     * */
049        public CacheArrayFilter(Long timer) {
050                super();
051                this.timer = timer;
052        }
053
054    /**
055     * New a CacheArrayFilter Object
056     * @param timer - Timer,default is 10ms
057     * @param loopTimer - Loop Timer,default is 10ms
058     * */
059        public CacheArrayFilter(Long timer,Long loopTimer) {
060                super();
061                this.timer = timer;
062                this.loopTimer = loopTimer;
063        }       
064
065    /**
066     * Need override the method to use
067     * @param index - Index of cache list
068     * @param o - Cache value
069     * */
070        public void execute(Integer index, Object o) {
071
072        }
073
074    /**
075     * Handle execute batch method
076     * */
077        public void executeBatch(Integer batchIndex,List batch){
078            
079        }
080        
081    /**
082     * Handle completed method
083     * */
084        public void completed(Integer size) {
085
086        }
087        
088    /**
089     * Handle terminated method
090     * */
091        public void terminated() {
092
093        }       
094        
095        public void terminate(){
096            this.terminated = true;
097        }
098        
099        public void forceTerminate(){
100            this.terminated = true;
101            this.forceTerminated = true;
102        }               
103        
104        public boolean isTerminated(){
105            return terminated;
106        }
107        
108        public boolean isForceTerminated(){
109            return forceTerminated;
110        }       
111        
112        public void setTimer(long timer) {
113                this.timer = timer;
114        }       
115
116        public Long getTimer() {
117                return timer;
118        }
119        
120        public void setLoopTimer(long loopTimer) {
121                this.loopTimer = loopTimer;
122        }       
123        
124        public Long getLoopTimer() {
125                return loopTimer;
126        }       
127
128        public void setCacheArray(CacheArray cacheArray) {
129                this.cacheArray = cacheArray;
130        }
131
132        public CacheArray getCacheArray() {
133                return this.cacheArray;
134        }       
135
136}