Java Code Examples for com.jstarcraft.core.utility.StringUtility#DOT

The following examples show how to use com.jstarcraft.core.utility.StringUtility#DOT . 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: StompEventChannel.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public void triggerEvent(Object event) {
    try {
        Class type = event.getClass();
        byte[] bytes = codec.encode(type, event);
        Map<String, String> metadatas = new HashMap<>();
        // TODO 需要防止路径冲突
        String channel = name + StringUtility.DOT + type.getName();
        metadatas.put("destination", channel);
        switch (mode) {
        case QUEUE: {
            // Artemis特定的协议
            metadatas.put("destination-type", "ANYCAST");
            break;
        }
        case TOPIC: {
            // Artemis特定的协议
            metadatas.put("destination-type", "MULTICAST");
            break;
        }
        }
        session.send(metadatas, Buffer.buffer(bytes));
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 2
Source File: StompEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void registerMonitor(Set<Class> types, EventMonitor monitor) {
    try {
        for (Class type : types) {
            EventManager manager = managers.get(type);
            if (manager == null) {
                manager = new EventManager();
                managers.put(type, manager);
                Map<String, String> metadatas = new HashMap<>();
                // TODO 需要防止路径冲突
                String address = name + StringUtility.DOT + type.getName();
                metadatas.put("destination", address);
                switch (mode) {
                case QUEUE: {
                    // Artemis特定的协议
                    metadatas.put("destination-type", "ANYCAST");
                    break;
                }
                case TOPIC: {
                    // Artemis特定的协议
                    metadatas.put("destination-type", "MULTICAST");
                    break;
                }
                }
                EventHandler handler = new EventHandler(type, manager);
                session.subscribe(address, metadatas, handler);
            }
            manager.attachMonitor(monitor);
        }
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 3
Source File: StompEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void unregisterMonitor(Set<Class> types, EventMonitor monitor) {
    try {
        for (Class type : types) {
            EventManager manager = managers.get(type);
            if (manager != null) {
                manager.detachMonitor(monitor);
                if (manager.getSize() == 0) {
                    managers.remove(type);
                    Map<String, String> metadatas = new HashMap<>();
                    // TODO 需要防止路径冲突
                    String address = name + StringUtility.DOT + type.getName();
                    metadatas.put("destination", address);
                    switch (mode) {
                    case QUEUE: {
                        // Artemis特定的协议
                        metadatas.put("destination-type", "ANYCAST");
                        break;
                    }
                    case TOPIC: {
                        // Artemis特定的协议
                        metadatas.put("destination-type", "MULTICAST");
                        break;
                    }
                    }
                    session.unsubscribe(address, metadatas);
                }
            }
        }
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 4
Source File: RocketEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void registerMonitor(Set<Class> types, EventMonitor monitor) {
    try {
        for (Class type : types) {
            EventManager manager = managers.get(type);
            if (manager == null) {
                manager = new EventManager();
                managers.put(type, manager);
                // TODO 需要防止路径冲突
                String address = name + StringUtility.DOT + type.getName();
                address = address.replace(StringUtility.DOT, StringUtility.DASH);
                DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(address);
                consumer.setInstanceName(name);
                consumer.setNamesrvAddr(connections);
                consumer.setConsumeMessageBatchMaxSize(1000);
                consumer.subscribe(address, "*");
                switch (mode) {
                case QUEUE: {
                    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
                    consumer.setMessageModel(MessageModel.CLUSTERING);
                    break;
                }
                case TOPIC: {
                    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
                    consumer.setMessageModel(MessageModel.BROADCASTING);
                    break;
                }
                }
                EventHandler handler = new EventHandler(type, manager);
                consumer.registerMessageListener(handler);
                consumer.start();
                consumers.put(type, consumer);
            }
            manager.attachMonitor(monitor);
        }
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 5
Source File: RocketEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void triggerEvent(Object event) {
    try {
        Class type = event.getClass();
        String address = name + StringUtility.DOT + type.getName();
        address = address.replace(StringUtility.DOT, StringUtility.DASH);
        byte[] bytes = codec.encode(type, event);
        Message message = new Message(address, address, bytes);
        producer.send(message);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 6
Source File: RabbitEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void registerMonitor(Set<Class> types, EventMonitor monitor) {
    try {
        for (Class type : types) {
            EventManager manager = managers.get(type);
            if (manager == null) {
                manager = new EventManager();
                managers.put(type, manager);

                String address = null;
                switch (mode) {
                case QUEUE: {
                    // 共享名称,不独占队列
                    address = name + StringUtility.DOT + type.getName();
                    channel.queueDeclare(address, true, false, false, null);
                    break;
                }
                case TOPIC: {
                    // 不共享名称,独占队列
                    address = name + StringUtility.DOT + type.getName() + UUID.randomUUID();
                    channel.queueDeclare(address, true, true, true, null);
                    break;
                }
                }
                String key = type.getName();
                channel.queueBind(address, name, key);

                EventHandler handler = new EventHandler(channel, type, manager);
                String tag = channel.basicConsume(address, false, handler);
                tags.put(type, tag);
            }
            manager.attachMonitor(monitor);
        }
    } catch (Exception exception) {
        exception.printStackTrace();
        throw new RuntimeException(exception);
    }
}
 
Example 7
Source File: KafkaEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void registerMonitor(Set<Class> types, EventMonitor monitor) {
    try {
        for (Class type : types) {
            EventManager manager = managers.get(type);
            String group = name + StringUtility.DOT + type.getName();
            if (manager == null) {
                manager = new EventManager();
                managers.put(type, manager);
                Properties properties = new Properties();
                properties.put("bootstrap.servers", connections);
                properties.put("key.deserializer", keyDeserializer);
                properties.put("value.deserializer", valueDeserializer);
                switch (mode) {
                case QUEUE: {
                    properties.put("group.id", group);
                    properties.put("auto.offset.reset", "earliest");
                    break;
                }
                case TOPIC: {
                    properties.put("group.id", group + UUID.randomUUID());
                    properties.put("auto.offset.reset", "latest");
                    break;
                }
                }
                KafkaConsumer<String, byte[]> consumer = new KafkaConsumer<>(properties);
                consumer.subscribe(Collections.singleton(group));
                // TODO 此处是为了防止auto.offset.reset为latest时,可能会丢失第一次poll之前的消息.
                updateAssignmentMetadata.invoke(consumer, Time.SYSTEM.timer(Long.MAX_VALUE));
                consumers.put(type, consumer);
                EventThread thread = new EventThread(type, manager);
                thread.start();
                threads.put(type, thread);
            }
            manager.attachMonitor(monitor);
        }
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 8
Source File: KafkaEventChannel.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public void triggerEvent(Object event) {
    try {
        Class type = event.getClass();
        String group = name + StringUtility.DOT + type.getName();
        byte[] bytes = codec.encode(type, event);
        ProducerRecord<String, byte[]> record = new ProducerRecord<>(group, bytes);
        producer.send(record);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}