当前位置: 首页>>代码示例>>Java>>正文


Java Ringbuffer类代码示例

本文整理汇总了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);
        }
    });
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:24,代码来源:HazelcastApplicationCommunicator.java

示例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);
}
 
开发者ID:ahome-it,项目名称:ahome-tooling-server-hazelcast,代码行数:15,代码来源:HazelcastContextInstance.java

示例3: getRingbuffer

import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public <E> Ringbuffer<E> getRingbuffer(String s) {
    return null;
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:5,代码来源:WebConfigurerTest.java

示例4: HazelcastApplicationWorker

import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
public HazelcastApplicationWorker(Ringbuffer<InternalMessage> applicationRing, ApplicationListener listener) {
    this.applicationRing = applicationRing;
    this.listener = listener;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:5,代码来源:HazelcastApplicationWorker.java

示例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);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:6,代码来源:HazelcastHttpCommunicator.java

示例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);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:6,代码来源:HazelcastHttpCommunicator.java

示例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);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:5,代码来源:HazelcastBrokerCommunicator.java

示例8: HazelcastBrokerWorker

import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
public HazelcastBrokerWorker(Ringbuffer<InternalMessage> brokerRing, BrokerListener listener) {
    this.brokerRing = brokerRing;
    this.listener = listener;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:5,代码来源:HazelcastBrokerWorker.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:49,代码来源:HazelcastRingbufferTest.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:56,代码来源:HazelcastRingbufferTest.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:49,代码来源:HazelcastRingbufferTest.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:75,代码来源:HazelcastRingbufferTest.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:75,代码来源:HazelcastRingbufferTest.java

示例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());
        }
    });
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:67,代码来源:HazelcastRingbufferTest.java

示例15: getRingbuffer

import com.hazelcast.ringbuffer.Ringbuffer; //导入依赖的package包/类
@Override
public <E> Ringbuffer<E> getRingbuffer(String name) {
    return instance.getRingbuffer(getPrefix(name));
}
 
开发者ID:lburgazzoli,项目名称:lb-hazelcast,代码行数:5,代码来源:HzPrefixedInstance.java


注:本文中的com.hazelcast.ringbuffer.Ringbuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。