Skip to content
Snippets Groups Projects
Commit 566501aa authored by Christian Wulf's avatar Christian Wulf
Browse files

added ConcurrentBlockingIntraThreadPipe + Factory

parent 5d3ab08c
No related branches found
No related tags found
No related merge requests found
package teetime.framework.pipe;
import java.util.concurrent.ConcurrentLinkedQueue;
import teetime.framework.AbstractIntraThreadPipe;
import teetime.framework.InputPort;
import teetime.framework.OutputPort;
public final class ConcurrentBlockingIntraThreadPipe<T> extends AbstractIntraThreadPipe {
private final ConcurrentLinkedQueue<Object> queue;
ConcurrentBlockingIntraThreadPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
super(sourcePort, targetPort);
queue = new ConcurrentLinkedQueue<Object>();
}
@Override
public boolean add(final Object element) {
return queue.add(element);
}
@Override
public boolean isEmpty() {
return queue.isEmpty();
}
@Override
public int size() {
return queue.size();
}
@Override
public Object removeLast() {
return queue.poll();
}
}
/**
* Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package teetime.framework.pipe;
import teetime.framework.InputPort;
import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public final class ConcurrentBlockingIntraThreadPipeFactory implements IPipeFactory {
@Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
return this.create(sourcePort, targetPort, 4);
}
@Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) {
return new ConcurrentBlockingIntraThreadPipe<T>(sourcePort, targetPort);
}
@Override
public ThreadCommunication getThreadCommunication() {
return ThreadCommunication.INTRA;
}
@Override
public PipeOrdering getOrdering() {
return PipeOrdering.QUEUE_BASED;
}
@Override
public boolean isGrowable() {
return true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment