public RingBufferChannelBuilder blockingTimeout(long nanos) { checkState(); data.setBlockingTimeoutNanos(nanos); return this; }
public RingBufferChannelBuilder phasedBlockingType(PhasedBlockingType type) { checkState(); data.setPhasedBlockingType(type); return this; }
public RingBufferChannelBuilder ringSize(int size) { checkState(); data.setRingSize(size); return this; }
public void load(Channel definition, XMLStreamReader reader, IntrospectionContext context) { Location startLocation = reader.getLocation(); RingBufferData data = new RingBufferData(); data.setRingSize(ringSize); try { RingBufferData.WaitStrategyType type = RingBufferData.WaitStrategyType.valueOf(waitStrategy.toUpperCase()); data.setWaitStrategy(type); } catch (IllegalArgumentException e) { context.addError(new InvalidValue("Invalid wait strategy", startLocation, definition)); data.setBlockingTimeoutNanos(blockingTimeout); data.setSpinTimeoutNanos(spinTimeout); data.setYieldTimeoutNanos(yieldTimeout); try { RingBufferData.PhasedBlockingType type = RingBufferData.PhasedBlockingType.valueOf(phasedBlockingStrategy.toUpperCase()); data.setPhasedBlockingType(type); } catch (IllegalArgumentException e) { context.addError(new InvalidValue("Invalid phased blocking type", startLocation, definition));
private WaitStrategy createWaitStrategy(RingBufferData data) { switch (data.getWaitStrategy()) { case YIELDING: return new YieldingWaitStrategy(); case SLEEPING: return new SleepingWaitStrategy(); case BACKOFF: if (RingBufferData.PhasedBlockingType.LOCK == data.getPhasedBlockingType()) { return PhasedBackoffWaitStrategy.withLock(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } else { return PhasedBackoffWaitStrategy.withSleep(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } case SPIN: return new BusySpinWaitStrategy(); case TIMEOUT: return new TimeoutBlockingWaitStrategy(data.getBlockingTimeoutNanos(), TimeUnit.NANOSECONDS); default: return new BlockingWaitStrategy(); } }
public RingBufferChannelBuilder waitStrategy(WaitStrategyType strategy) { checkState(); data.setWaitStrategy(strategy); return this; }
public RingBufferChannelBuilder yieldTimeout(long nanos) { checkState(); data.setYieldTimeoutNanos(nanos); return this; }
public RingBufferChannelBuilder spinTimeout(long nanos) { checkState(); data.setSpinTimeoutNanos(nanos); return this; }
protected RingBufferChannelBuilder(String name) { definition = new Channel(name); data = new RingBufferData(); definition.setMetadata(data); }
public Channel build(PhysicalChannel physicalChannel) throws Fabric3Exception { URI uri = physicalChannel.getUri(); URI contributionUri = physicalChannel.getContributionUri(); RingBufferData data = physicalChannel.getMetadata(RingBufferData.class); int size = data.getRingSize(); WaitStrategy strategy = createWaitStrategy(data); ChannelSide channelSide = physicalChannel.getChannelSide(); return new RingBufferChannel(uri, size, strategy, channelSide, executorService, contributionUri); }