com.alibaba.rocketmq.store.MessageStore Java Examples

The following examples show how to use com.alibaba.rocketmq.store.MessageStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageStoreFactory.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
        throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                AbstractPluginMessageStore pluginMessageStore = (AbstractPluginMessageStore) construct.newInstance(context, messageStore);
                messageStore = pluginMessageStore;
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                        "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #2
Source File: PlugInTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageStoreFactory() throws IOException {
    BrokerConfig brokerConfig = new BrokerConfig();
    MessageStorePluginContext context = new MessageStorePluginContext(null, null, null, brokerConfig);
    MessageStore messageStore = null;
    AbstractPluginMessageStore m = null;
    //��plugin����
    brokerConfig.setMessageStorePlugIn(null);
    messageStore = MessageStoreFactory.build(context, new MockMessageStore());
    assertTrue(messageStore instanceof MockMessageStore);

    brokerConfig.setMessageStorePlugIn("");
    messageStore = MessageStoreFactory.build(context, new MockMessageStore());
    assertTrue(messageStore instanceof MockMessageStore);

    //��plugin����
    brokerConfig.setMessageStorePlugIn("com.alibaba.rocketmq.broker.plugin.MockMessageStorePlugin1,com.alibaba.rocketmq.broker.plugin.MockMessageStorePlugin2");
    messageStore = MessageStoreFactory.build(context, new MockMessageStore());
    assertTrue(messageStore instanceof MockMessageStorePlugin1);
    m = (AbstractPluginMessageStore) messageStore;

    assertTrue(m.next instanceof MockMessageStorePlugin2);
    m = (AbstractPluginMessageStore) m.next;
    assertTrue(m.next instanceof MockMessageStore);

    //�׳��쳣����
    brokerConfig.setMessageStorePlugIn("aaaaaa");
    try {
        messageStore = MessageStoreFactory.build(context, new MockMessageStore());
        assertTrue(false);
    } catch (RuntimeException e) {
    }

}
 
Example #3
Source File: BrokerController.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #4
Source File: BrokerController.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #5
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #6
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #7
Source File: PlugInTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void testAbstractPluginMessageStore() throws IllegalAccessException, IllegalArgumentException,
        InvocationTargetException {


    final ThreadLocal<String> invokingMethodName = new ThreadLocal<String>();

    MessageStore messageStore = (MessageStore) Proxy.newProxyInstance(
            MessageStore.class.getClassLoader(), new Class[]{MessageStore.class},
            new InvocationHandler() {
                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                    assertEquals(invokingMethodName.get(), method.getName());
                    if (method.getReturnType() == int.class) {
                        return Integer.valueOf(0);
                    } else if (method.getReturnType() == long.class) {
                        return Long.valueOf(0);
                    } else if (method.getReturnType() == char.class) {
                        return Byte.valueOf((byte) 0);
                    } else if (method.getReturnType() == byte.class) {
                        return Byte.valueOf((byte) 0);
                    } else if (method.getReturnType() == boolean.class) {
                        return true;
                    } else {
                        return null;
                    }
                }
            });

    AbstractPluginMessageStore pluginMessageStore = new AbstractPluginMessageStore(null, messageStore) {

        @Override
        public boolean isOSPageCacheBusy() {
            return false;
        }
    };

    Method[] methods = MessageStore.class.getMethods();
    for (Method m : methods) {
        Class[] paramType = m.getParameterTypes();
        Object[] mockParam = new Object[paramType.length];
        for (int i = 0; i < paramType.length; ++i) {
            if (paramType[i] == int.class) {
                mockParam[i] = Integer.valueOf(0);
            } else if (paramType[i] == long.class) {
                mockParam[i] = Long.valueOf(0);
            } else if (paramType[i] == byte.class) {
                mockParam[i] = Byte.valueOf((byte)0);
            } else if (paramType[i] == char.class) {
                mockParam[i] = Byte.valueOf((byte)0);
            } else
                mockParam[i] = null;
        }
        invokingMethodName.set(m.getName());
        m.invoke(pluginMessageStore, mockParam);
    }
}
 
Example #8
Source File: BrokerController.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #9
Source File: BrokerController.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #10
Source File: MockMessageStorePlugins.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
/**
 * @param context
 * @param next
 */
public MockMessageStorePlugin1(MessageStorePluginContext context, MessageStore next) {
    super(context, next);
}
 
Example #11
Source File: MockMessageStorePlugins.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
/**
 * @param context
 * @param next
 */
public MockMessageStorePlugin2(MessageStorePluginContext context, MessageStore next) {
    super(context, next);
}