org.apache.commons.collections.buffer.CircularFifoBuffer Java Examples

The following examples show how to use org.apache.commons.collections.buffer.CircularFifoBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CircularCharArrayBufferTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("boxing")
public void testAdd() {
	for ( int size: sizes ) {
		System.out.printf( "CIRCULAR BUFFER OF SIZE %d: ", size );
		CircularFifoBuffer cfb = new CircularFifoBuffer( size );
		CircularCharArrayBuffer ccab = new CircularCharArrayBuffer( size );
		int times = r.nextInt( 50 );
		System.out.println( times + " times" );
		for ( int j = 0; j < times; j++ ) {
			char[] c = new char[ 1 + r.nextInt( 1 + size * 10 / 2 ) ];
			int offset = r.nextInt( c.length );
			int len = r.nextInt( c.length - offset );
			System.arraycopy( RandomStringUtils.randomAlphanumeric( c.length ).toCharArray(), 0, c, 0, c.length );
			for ( int i = offset; i < offset + len; i++ )
				cfb.add( new Character( c[ i ] ) );
			ccab.add( c, offset, len );
			char[] res = new char[ cfb.size() ];
			copyInto( cfb, res, 0, cfb.size() );
			char[] res2 = new char[ cfb.size() ];
			ccab.toCharArray( res2, 0, cfb.size() );
			assertEquals( new String( res ), new String( res2 ) );
		}
	}
}
 
Example #2
Source File: Lag.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void eval(FunctionContext ctx, Tuple params) {
  LagContext lagCtx = (LagContext)ctx;
  if(lagCtx.lagBuffer == null) {
    int lagNum = 0;
    if (params.size() == 1) {
      lagNum = 1;
    } else {
      lagNum = params.getInt4(1);
    }
    lagCtx.lagBuffer = new CircularFifoBuffer(lagNum+1);
  }

  if (!params.isBlankOrNull(0)) {
    lagCtx.lagBuffer.add(params.asDatum(0));
  } else {
    lagCtx.lagBuffer.add(NullDatum.get());
  }

  if (lagCtx.defaultDatum == null) {
   if (params.size() == 3) {
     lagCtx.defaultDatum = params.asDatum(2);
   } else {
     lagCtx.defaultDatum = NullDatum.get();
   }
  }
}
 
Example #3
Source File: NthLastModifiedTimeTracker.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public NthLastModifiedTimeTracker(int numTimesToTrack) {
    if (numTimesToTrack < 1) {
        throw new IllegalArgumentException(
                "numTimesToTrack must be greater than zero (you requested " + numTimesToTrack + ")");
    }
    lastModifiedTimesMillis = new CircularFifoBuffer(numTimesToTrack);
    initLastModifiedTimesMillis();
}
 
Example #4
Source File: CircularQueueLogAppender.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@PluginFactory
public static CircularQueueLogAppender createAppender(
    @PluginAttribute(value = "name") String name,
    @PluginElement(value = "Filters") Filter filter,
    @PluginElement(value = "Layout") Layout<? extends Serializable> layout,
    @PluginAttribute(value = "ignoreExceptions") boolean ignoreExceptions,
    @PluginAttribute(value = "maxQueueSize") int maxQueueSize,
    @PluginAttribute(value = "dateFormat") String dateFormat,
    @PluginAttribute(value = "global") boolean global) {

    if (StringUtils.isEmpty(name)) {
        LOGGER.error("No name provided for " + PLUGIN_NAME);
        return null;
    }

    if (Objects.isNull(layout)) {
        layout = PatternLayout.createDefaultLayout();
    }

    if (Objects.isNull(buffer)) {
        LOGGER.debug("Initializing circular log queue buffer");
        if (maxQueueSize <= 0) {
            throw new IllegalArgumentException("maxQueueSize must be a integer bigger that 0");
        }
        buffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(maxQueueSize));
    }

    CircularQueueLogAppender appender = new CircularQueueLogAppender(name, filter, layout, ignoreExceptions, null);
    appender.dateFormat = DateTimeFormatter.ofPattern(dateFormat).withZone(ZoneId.of("UTC"));
    appender.global = global;

    return appender;
}
 
Example #5
Source File: NthLastModifiedTimeTracker.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
public NthLastModifiedTimeTracker(int numTimesToTrack) {
  if (numTimesToTrack < 1) {
    throw new IllegalArgumentException(
        "numTimesToTrack must be greater than zero (you requested " + numTimesToTrack + ")");
  }
  lastModifiedTimesMillis = new CircularFifoBuffer(numTimesToTrack);
  initLastModifiedTimesMillis();
}
 
Example #6
Source File: MqRunnerComponent.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initMappings() {
    if (properties.isManagerNotDefined()) {
        log.warn("MQ manager not defined, skip JMS mappings initialization");
        return;
    }
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(properties.getRequestBufferSize()));
    repository.load().getMappings().forEach(this::applyMapping);
}
 
Example #7
Source File: ReportsArchiver.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Autowired
public ReportsArchiver(ExecutionStateRepository stateRespository, JdbcInserter jdbc) {
	client = new ArchiverHttpClient(Configuration.INSTANCE.readString(ConfigProps.ARCHIVER_DIFIDO_SERVER));
	enabled = Configuration.INSTANCE.readBoolean(ConfigProps.ARCHIVER_ENABLED);
	final int minReportsAge = Configuration.INSTANCE.readInt(ConfigProps.ARCHIVER_MIN_REPORTS_AGE);
	minReportsAgeInMillis = TimeUnit.DAYS.toMillis(minReportsAge);
	reportsFolder = Configuration.INSTANCE.readString(ConfigProps.DOC_ROOT_FOLDER) + File.separator
			+ Common.REPORTS_FOLDER_NAME;
	maxToArchive = Configuration.INSTANCE.readInt(ConfigProps.ARCHIVER_MAX_TO_ARCHIVE);
	archiveHistory = new CircularFifoBuffer(MAX_RECORDS_IN_HISTORY);
	this.stateRespository = stateRespository;
	this.jdbc = jdbc;
}
 
Example #8
Source File: NthLastModifiedTimeTracker.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
public NthLastModifiedTimeTracker(int numTimesToTrack) {
    if (numTimesToTrack < 1) {
        throw new IllegalArgumentException(
            "numTimesToTrack must be greater than zero (you requested " + numTimesToTrack + ")");
    }
    lastModifiedTimesMillis = new CircularFifoBuffer(numTimesToTrack);
    initLastModifiedTimesMillis();
}
 
Example #9
Source File: NthLastModifiedTimeTracker.java    From storm_spring_boot_demo with MIT License 5 votes vote down vote up
public NthLastModifiedTimeTracker(int numTimesToTrack) {
  if (numTimesToTrack < 1) {
    throw new IllegalArgumentException(
        "numTimesToTrack must be greater than zero (you requested " + numTimesToTrack + ")");
  }
  lastModifiedTimesMillis = new CircularFifoBuffer(numTimesToTrack);
  initLastModifiedTimesMillis();
}
 
Example #10
Source File: AbstractRequestBlock.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public Statistics ( final DataItemFactory itemFactory, final int size )
{
    this.stateItem = itemFactory.createInput ( "state", null );
    this.timeoutStateItem = itemFactory.createInput ( "timeout", null );
    this.lastUpdateItem = itemFactory.createInput ( "lastUpdate", null );
    this.lastTimeDiffItem = itemFactory.createInput ( "lastDiff", null );
    this.avgDiffItem = itemFactory.createInput ( "avgDiff", null );
    this.checksumErrorsItem = itemFactory.createInput ( "checksumErrors", null );

    this.sizeItem = itemFactory.createInput ( "size", null );
    this.sizeItem.updateData ( Variant.valueOf ( size ), null, null );

    this.lastUpdate = System.currentTimeMillis ();
    this.diffBuffer = new CircularFifoBuffer ( 20 );
}
 
Example #11
Source File: ApiControllerTest.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
public ApiControllerTest() throws NoSuchFieldException, IllegalAccessException {
    MqRunnerComponent mqRunnerComponent = new MqRunnerComponent(new MqProperties(), new DummyJmsMappingsRepository());
    Field fifo = MqRunnerComponent.class.getDeclaredField("fifo");
    fifo.setAccessible(true);
    fifo.set(mqRunnerComponent, BufferUtils.synchronizedBuffer(new CircularFifoBuffer(BUFF_SIZE)));

    for (int i = 0; i < BUFF_SIZE; i++) {
        MockedRequest mockedRequest = new MockedRequest();
        mockedRequest.setDate(Date.from(LocalDateTime.of(2000 + i, 1, 1, 6, 30).atZone(ZoneId.systemDefault()).toInstant()));
        Buffer b = mqRunnerComponent.getFifo();
        b.add(mockedRequest);
    }

    apiController = new ApiController(mqRunnerComponent);
}
 
Example #12
Source File: CircularCharArrayBufferTest.java    From database with GNU General Public License v2.0 4 votes vote down vote up
private static void copyInto( CircularFifoBuffer cfb, char[] c, int offset, int length ) {
	int howMany = Math.min( length, cfb.size() );
	Iterator<?> it = cfb.iterator();
	for ( int i = 0; i < howMany; i++ ) 
		c[ offset + i ] = ((Character)it.next()).charValue();
}
 
Example #13
Source File: DefaultBlockReleaseStrategy.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public DefaultBlockReleaseStrategy(int period)
{
  freeBlockNumQueue = new CircularFifoBuffer(period);
}
 
Example #14
Source File: NotificationList.java    From juddi with Apache License 2.0 4 votes vote down vote up
private NotificationList() {	
	list = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(10));
}
 
Example #15
Source File: ChannelBuffer.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public ChannelBuffer(final String name, final int bufferSize) {
	this.channelName = name;
	this.messageBuffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(bufferSize));
	this.size = bufferSize;
}
 
Example #16
Source File: ChannelBuffer.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public void createChannelBuffer() {
	this.messageBuffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(MAX_BUFFER_SIZE));
	this.size = MAX_BUFFER_SIZE;
}
 
Example #17
Source File: ChannelBuffer.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public void createChannelBuffer(final int bufferSize) {
	this.messageBuffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(bufferSize));
	this.size = bufferSize;
}
 
Example #18
Source File: MfccService.java    From android-speaker-audioanalysis with MIT License 2 votes vote down vote up
/**
 * Handles of all necessary initializations
 */
private boolean init() {

 
      //broadcaster = LocalBroadcastManager.getInstance(this);

      fileOprObj = new FileOperations();
      monitorOprObj = new MonitoringData(this, fileOprObj);
      
      vadOprObj = new VadManager(getApplicationContext());        //loads Vad model as well in the constructor 
      vadPredictionList = new DescriptiveStatistics();
speechWindowBuffer = new CircularFifoBuffer(12);

      
      simulateOprObj = new Simulation();
      simulateOprObj.scenario2();//Setting Simulation Scenario
     
      notifManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

      synchronized (this) {
	if (backgroundThread == null) {
		
        backgroundThread = new Thread(new Runnable() {
			//For the resource intensive tasks
        	
			@Override
			public void run() {
				// TODO Auto-generated method stub
		        Log.i(TAG, "onCreate thread running..");
		        handleRecordingAudio();
		        updateNotification("extraction mode");
			}
		});
	}
      }
      
      Log.i(TAG, "init()");
      
      //recordingExecService = Executors.newCachedThreadPool();     
      scheduleExecService = Executors.newScheduledThreadPool(5);
      
      return true;


}