本文整理汇总了Java中com.hazelcast.ringbuffer.Ringbuffer类的典型用法代码示例。如果您正苦于以下问题:Java Ringbuffer类的具体用法?Java Ringbuffer怎么用?Java Ringbuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ringbuffer类属于com.hazelcast.ringbuffer包,在下文中一共展示了Ringbuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
/**
* Send internal message to hazelcast ring
*
* @param ring Hazelcast RingBuffer
* @param message Internal Message
*/
protected void sendMessage(Ringbuffer<InternalMessage> ring, InternalMessage message) {
ring.addAsync(message, OverflowPolicy.OVERWRITE).andThen(new ExecutionCallback<Long>() {
@Override
public void onResponse(Long response) {
if (response > 0) {
logger.debug("Communicator succeed: Successful add message {} to ring buffer {}", message.getMessageType(), ring.getName());
} else {
logger.debug("Communicator failed: Failed to add message {} to ring buffer {}: no space", message.getMessageType(), ring.getName());
}
}
@Override
public void onFailure(Throwable t) {
logger.warn("Communicator failed: Failed to add message {} to ring buffer {}: ", message.getMessageType(), ring.getName(), t);
}
});
}
示例2: getRingbuffer
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <E> Ringbuffer<E> getRingbuffer(String name)
{
name = Objects.requireNonNull(name);
final Ringbuffer<E> valu = getBeanSafely(name, Ringbuffer.class);
if (null != valu)
{
return valu;
}
return hz().getRingbuffer(name);
}
示例3: getRingbuffer
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public <E> Ringbuffer<E> getRingbuffer(String s) {
return null;
}
示例4: HazelcastApplicationWorker
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
public HazelcastApplicationWorker(Ringbuffer<InternalMessage> applicationRing, ApplicationListener listener) {
this.applicationRing = applicationRing;
this.listener = listener;
}
示例5: sendToBroker
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public void sendToBroker(String brokerId, InternalMessage message) {
Ringbuffer<InternalMessage> ring = this.hazelcast.getRingbuffer(BROKER_TOPIC_PREFIX + "." + brokerId);
sendMessage(ring, message);
}
示例6: sendToApplication
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public void sendToApplication(InternalMessage message) {
Ringbuffer<InternalMessage> ring = this.hazelcast.getRingbuffer(APPLICATION_TOPIC);
sendMessage(ring, message);
}
示例7: sendToBroker
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
public void sendToBroker(String brokerId, InternalMessage message) {
Ringbuffer<InternalMessage> ring = this.hazelcast.getRingbuffer(BROKER_TOPIC_PREFIX + "." + brokerId);
sendMessage(ring, message);
}
示例8: HazelcastBrokerWorker
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
public HazelcastBrokerWorker(Ringbuffer<InternalMessage> brokerRing, BrokerListener listener) {
this.brokerRing = brokerRing;
this.listener = listener;
}
示例9: testSimpleRingbuffer
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testSimpleRingbuffer() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("default");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(100L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(0L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element1");
currentSequence++;
String lastElement = null;
while (ringbuffer.size() > 0) {
lastElement = ringbuffer.readOne(currentSequence);
assertThat(lastElement)
.isNotNull();
if (currentSequence == 99) {
break;
}
currentSequence++;
}
assertThat(lastElement)
.isEqualTo("element100");
assertThat(ringbuffer.headSequence())
.isEqualTo(0L);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
} catch (InterruptedException e) {
fail(e.getMessage());
}
});
}
示例10: testRingbufferReadMany
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testRingbufferReadMany() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("default");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(100L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(0L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element1");
currentSequence++;
ICompletableFuture<ReadResultSet<String>> completableFuture =
ringbuffer
.readManyAsync(currentSequence, 1, 10, null);
ReadResultSet<String> readResultSet = completableFuture.get();
int readCount = readResultSet.readCount();
List<String> resultElements =
IntStream
.range(0, readCount)
.mapToObj(i -> readResultSet.get(i))
.collect(Collectors.toList());
List<String> verifyResultElements =
IntStream
.range(2, readCount + 2)
.mapToObj(i -> "element" + i)
.collect(Collectors.toList());
assertThat(resultElements)
.isEqualTo(verifyResultElements);
currentSequence += readCount;
assertThat(currentSequence)
.isEqualTo(headSequence + readCount + 1);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
});
}
示例11: testRingbufferOverflow
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testRingbufferOverflow() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("small-ringbuffer");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(10L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(90L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element91");
currentSequence++;
String lastElement = null;
while (ringbuffer.size() > 0) {
lastElement = ringbuffer.readOne(currentSequence);
assertThat(lastElement)
.isNotNull();
if (currentSequence == 99) {
break;
}
currentSequence++;
}
assertThat(lastElement)
.isEqualTo("element100");
assertThat(ringbuffer.headSequence())
.isEqualTo(90L);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
} catch (InterruptedException e) {
fail(e.getMessage());
}
});
}
示例12: testRingbufferSize
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testRingbufferSize() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("default");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(100L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(0L);
long tailSequence = ringbuffer.tailSequence();
assertThat(tailSequence)
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(10000L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element1");
currentSequence++;
ICompletableFuture<ReadResultSet<String>> completableFuture =
ringbuffer
.readManyAsync(currentSequence, 5, 10, null);
ReadResultSet<String> readResultSet = completableFuture.get();
int readCount = readResultSet.readCount();
currentSequence += readCount;
String lastElement = null;
while (ringbuffer.size() > 0) {
lastElement = ringbuffer.readOne(currentSequence);
assertThat(lastElement)
.isNotNull();
if (currentSequence == 99) {
break;
}
currentSequence++;
}
assertThat(lastElement)
.isEqualTo("element100");
assertThat(ringbuffer.headSequence())
.isEqualTo(0L);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(10000L);
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
});
}
示例13: testRingbufferSizeWithExpiry
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testRingbufferSizeWithExpiry() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("with-expired");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(100L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(0L);
long tailSequence = ringbuffer.tailSequence();
assertThat(tailSequence)
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(9900L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element1");
currentSequence++;
ICompletableFuture<ReadResultSet<String>> completableFuture =
ringbuffer
.readManyAsync(currentSequence, 5, 10, null);
ReadResultSet<String> readResultSet = completableFuture.get();
int readCount = readResultSet.readCount();
currentSequence += readCount;
String lastElement = null;
while (ringbuffer.size() > 0) {
lastElement = ringbuffer.readOne(currentSequence);
assertThat(lastElement)
.isNotNull();
if (currentSequence == 99) {
break;
}
currentSequence++;
}
assertThat(lastElement)
.isEqualTo("element100");
assertThat(ringbuffer.headSequence())
.isEqualTo(0L);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(9900L);
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
});
}
示例14: testRingbufferWithExpiry
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Test
public void testRingbufferWithExpiry() {
withHazelcast(1, hazelcast -> {
Ringbuffer<String> ringbuffer = hazelcast.getRingbuffer("with-expired");
IntStream.rangeClosed(1, 100).forEach(i -> ringbuffer.add("element" + i));
assertThat(ringbuffer.size())
.isEqualTo(100L);
long headSequence = ringbuffer.headSequence();
assertThat(headSequence)
.isEqualTo(0L);
long tailSequence = ringbuffer.tailSequence();
assertThat(tailSequence)
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(9900L);
try {
long currentSequence = headSequence;
assertThat(ringbuffer.readOne(currentSequence))
.isEqualTo("element1");
currentSequence++;
ICompletableFuture<ReadResultSet<String>> completableFuture =
ringbuffer
.readManyAsync(currentSequence, 5, 10, null);
ReadResultSet<String> readResultSet = completableFuture.get();
int readCount = readResultSet.readCount();
currentSequence += readCount;
TimeUnit.SECONDS.sleep(5);
long seq1 = currentSequence++;
assertThatThrownBy(() -> ringbuffer.readOne(seq1))
.isInstanceOf(StaleSequenceException.class);
long seq2 = currentSequence++;
assertThatThrownBy(() -> ringbuffer.readOne(seq2))
.isInstanceOf(StaleSequenceException.class);
assertThat(ringbuffer.headSequence())
.isEqualTo(100L);
assertThat(ringbuffer.tailSequence())
.isEqualTo(99L);
assertThat(ringbuffer.capacity())
.isEqualTo(10000L);
assertThat(ringbuffer.remainingCapacity())
.isEqualTo(10000L);
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
});
}
示例15: getRingbuffer
import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public <E> Ringbuffer<E> getRingbuffer(String name) {
return instance.getRingbuffer(getPrefix(name));
}