Java tutorial
/** * This file is part of the Paxle project. * Visit http://www.paxle.net for more information. * Copyright 2007-2010 the original author or authors. * * Licensed under the terms of the Common Public License 1.0 ("CPL 1.0"). * Any use, reproduction or distribution of this program constitutes the recipient's acceptance of this agreement. * The full license text is available under http://www.opensource.org/licenses/cpl1.0.txt * or in the file LICENSE.txt in the root directory of the Paxle distribution. * * Unless required by applicable law or agreed to in writing, this software is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ package org.paxle.tools.logging.impl; import java.util.Map; import org.apache.commons.collections.Buffer; import org.apache.commons.collections.BufferUtils; import org.apache.commons.collections.buffer.CircularFifoBuffer; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; import org.paxle.tools.logging.ILogData; import org.paxle.tools.logging.ILogReader; import edu.umd.cs.findbugs.annotations.OverrideMustInvoke; import edu.umd.cs.findbugs.annotations.When; @Component(componentAbstract = true) @Service(ILogReader.class) public abstract class ALogReader implements ILogReader { @Property(intValue = 200) public static final String BUFFER_SIZE = "bufferSize"; /** * A internal buffer for logging-messages */ protected Buffer fifo = null; @OverrideMustInvoke @Activate protected void activate(Map<String, Object> props) { // configuring the buffer Integer bufferSize = Integer.valueOf(200); if (props.containsKey(BUFFER_SIZE)) { bufferSize = (Integer) props.get(BUFFER_SIZE); } this.fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(bufferSize)); } @OverrideMustInvoke(When.LAST) @Deactivate protected void deactivate() { if (this.fifo != null) { // clear messages this.fifo.clear(); this.fifo = null; } } public void clear() { if (this.fifo != null) { fifo.clear(); } } @SuppressWarnings("unchecked") public ILogData getLogData() { return new LogData(this.fifo); } }