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


Java MqttTopicSubscription类代码示例

本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttTopicSubscription的典型用法代码示例。如果您正苦于以下问题:Java MqttTopicSubscription类的具体用法?Java MqttTopicSubscription怎么用?Java MqttTopicSubscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MqttTopicSubscription类属于io.netty.handler.codec.mqtt包,在下文中一共展示了MqttTopicSubscription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
public static void subscribe(MqttSubscribeMessage message, ClientIdentifier identifier){
    for(MqttTopicSubscription topicSubscription : message.payload().topicSubscriptions()){
        Topic topic = new Topic(topicSubscription.topicName());
        Topic.Element element = topic.getHeadElement();
        if (element == null) return;
        SubscriptionTree cachedTree = subscriptions.get(element.getValue());
        if(cachedTree == null){
            SubscriptionTree tree = new SubscriptionTree();
            tree.build(topic);
            subscriptions.putIfAbsent(element.getValue(), tree);
            tree.subscribe(topic,identifier);
        } else {
            cachedTree.subscribe(topic,identifier);
        }
    }
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:17,代码来源:SubscriptionCache.java

示例2: addSubscription

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
boolean addSubscription(MqttTopicSubscription subscription, WildcardConfiguration wildcardConfiguration) {
   synchronized (subscriptions) {
      addressMessageMap.putIfAbsent(MQTTUtil.convertMQTTAddressFilterToCore(subscription.topicName(), wildcardConfiguration), new ConcurrentHashMap<Long, Integer>());

      MqttTopicSubscription existingSubscription = subscriptions.get(subscription.topicName());
      if (existingSubscription != null) {
         if (subscription.qualityOfService().value() > existingSubscription.qualityOfService().value()) {
            subscriptions.put(subscription.topicName(), subscription);
            return true;
         }
      } else {
         subscriptions.put(subscription.topicName(), subscription);
         return true;
      }
   }
   return false;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:18,代码来源:MQTTSessionState.java

示例3: addSubscription

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
private void addSubscription(MqttTopicSubscription subscription) throws Exception {
   String topicName = CompositeAddress.extractAddressName(subscription.topicName());
   MqttTopicSubscription s = session.getSessionState().getSubscription(topicName);

   int qos = subscription.qualityOfService().value();

   String coreAddress = MQTTUtil.convertMQTTAddressFilterToCore(topicName, session.getWildcardConfiguration());

   session.getSessionState().addSubscription(subscription, session.getWildcardConfiguration());

   Queue q = createQueueForSubscription(coreAddress, qos);

   if (s == null) {
      createConsumerForSubscriptionQueue(q, topicName, qos);
   } else {
      consumerQoSLevels.put(consumers.get(topicName).getID(), qos);
   }
   session.getRetainMessageManager().addRetainedMessagesToQueue(q, topicName);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:MQTTSubscriptionManager.java

示例4: authSubscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
@Override
public List<MqttGrantedQoS> authSubscribe(String clientId, String userName, List<MqttTopicSubscription> requestSubscriptions) {
    List<MqttGrantedQoS> r = new ArrayList<>();
    requestSubscriptions.forEach(subscription -> {
        if (!this.allowDollar && subscription.topic().startsWith("$")) r.add(MqttGrantedQoS.FAILURE);
        if (subscription.topic().equals(this.deniedTopic)) r.add(MqttGrantedQoS.FAILURE);
        r.add(MqttGrantedQoS.valueOf(subscription.requestedQos().value()));
    });
    return r;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:11,代码来源:DummyAuthenticator.java

示例5: authSubscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
@Override
public List<MqttGrantedQoS> authSubscribe(String clientId, String userName, List<MqttTopicSubscription> requestSubscriptions) {
    List<MqttGrantedQoS> r = new ArrayList<>();
    requestSubscriptions.forEach(subscription -> {
        if (!this.allowDollar && subscription.topic().startsWith("$")) r.add(MqttGrantedQoS.FAILURE);
        if (subscription.topic().equals(this.deniedTopic)) r.add(MqttGrantedQoS.FAILURE);
        if (!subscription.topic().endsWith("downstream")) r.add(MqttGrantedQoS.FAILURE);
        if (subscription.topic().indexOf(clientId) == -1) r.add(MqttGrantedQoS.FAILURE);
        r.add(MqttGrantedQoS.valueOf(subscription.requestedQos().value()));
    });
    return r;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:13,代码来源:PowerAuthenticator.java

示例6: subscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
public static MqttSubscribeMessage subscribe(int messageId, MqttTopicSubscription... topicSubscriptions) {
	int topicNameSize = 0;
	int topicCount = topicSubscriptions.length;

	for (MqttTopicSubscription item : topicSubscriptions) {
		topicNameSize += item.topicName().getBytes(CharsetUtil.UTF_8).length;
	}

	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBSCRIBE, false, MqttQoS.AT_LEAST_ONCE,
			false, 2 + topicNameSize + topicCount);
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
	MqttSubscribePayload payload = new MqttSubscribePayload(Lists.newArrayList(topicSubscriptions));

	return new MqttSubscribeMessage(fixedHeader, variableHeader, payload);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:16,代码来源:MqttMessageFactory.java

示例7: authSubscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
@Override
public List<MqttGrantedQoS> authSubscribe(String clientId, String userName, List<MqttTopicSubscription> requestSubscriptions) {
    List<MqttGrantedQoS> r = new ArrayList<>();
    requestSubscriptions.forEach(subscription -> {
        if (!this.allowDollar && subscription.topic().startsWith("$")) r.add(MqttGrantedQoS.NOT_GRANTED);
        else if (subscription.topic().equals(this.deniedTopic)) r.add(MqttGrantedQoS.NOT_GRANTED);
        else r.add(MqttGrantedQoS.valueOf(subscription.requestedQos().value()));
    });
    return r;
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:11,代码来源:DummyAuthenticatorImpl.java

示例8: start

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
synchronized void start() throws Exception {
   for (MqttTopicSubscription subscription : session.getSessionState().getSubscriptions()) {
      String coreAddress = MQTTUtil.convertMQTTAddressFilterToCore(subscription.topicName(), session.getWildcardConfiguration());
      Queue q = createQueueForSubscription(coreAddress, subscription.qualityOfService().value());
      createConsumerForSubscriptionQueue(q, subscription.topicName(), subscription.qualityOfService().value());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:8,代码来源:MQTTSubscriptionManager.java

示例9: addSubscriptions

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
/**
 * As per MQTT Spec.  Subscribes this client to a number of MQTT topics.
 *
 * @param subscriptions
 * @return An array of integers representing the list of accepted QoS for each topic.
 * @throws Exception
 */
int[] addSubscriptions(List<MqttTopicSubscription> subscriptions) throws Exception {
   int[] qos = new int[subscriptions.size()];

   for (int i = 0; i < subscriptions.size(); i++) {
      addSubscription(subscriptions.get(i));
      qos[i] = subscriptions.get(i).qualityOfService().value();
   }
   return qos;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:MQTTSubscriptionManager.java

示例10: processSubscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
private void processSubscribe(ChannelHandlerContext ctx, MqttSubscribeMessage mqttMsg) {
  if (!checkConnected(ctx)) {
    return;
  }
  log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId());
  List<Integer> grantedQoSList = new ArrayList<>();
  for (MqttTopicSubscription subscription : mqttMsg.payload().topicSubscriptions()) {
    String topicName = subscription.topicName();
    // TODO: handle this qos level.
    MqttQoS reqQoS = subscription.qualityOfService();
    try {
      if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
        // AdaptorToSessionActorMsg msg =
        // adaptor.convertToActorMsg(deviceSessionCtx,
        // SUBSCRIBE_ATTRIBUTES_REQUEST,
        // mqttMsg);
        // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new
        // BasicToDeviceActorSessionMsg(
        // deviceSessionCtx.getDevice(), msg);
        // processor.process(basicToDeviceActorSessionMsg);
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_RPC_REQUESTS_SUB_TOPIC)) {
        // AdaptorToSessionActorMsg msg =
        // adaptor.convertToActorMsg(deviceSessionCtx,
        // SUBSCRIBE_RPC_COMMANDS_REQUEST,
        // mqttMsg);
        // processor.process(new
        // BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), msg));
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_RPC_RESPONSE_SUB_TOPIC)) {
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_ATTRIBUTES_RESPONSES_TOPIC)) {
        deviceSessionCtx.setAllowAttributeResponses();
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_TELEMETRY_TOPIC)) {
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else {
        log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
        grantedQoSList.add(FAILURE.value());
      }
      ChannelEntity channelEntity = new TcpChannelEntity(ctx.channel());
      MemoryMetaPool.registerTopic(channelEntity, topicName);
    } catch (Exception e) {
      e.printStackTrace();
      log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
      grantedQoSList.add(FAILURE.value());
    }
  }

  ctx.writeAndFlush(createSubAckMessage(mqttMsg.variableHeader().messageId(), grantedQoSList));
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:52,代码来源:MqttTransportHandler.java

示例11: subscribe

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
public void subscribe(MqttTopicSubscription... topicSubscriptions) throws InterruptedException {
	send(MqttMessageFactory.subscribe(nextMessageId(), topicSubscriptions));

	// TODO error handling,store subscription
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:6,代码来源:MqttClient.java

示例12: getSubscriptions

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
Collection<MqttTopicSubscription> getSubscriptions() {
   return subscriptions.values();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:4,代码来源:MQTTSessionState.java

示例13: getSubscription

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
MqttTopicSubscription getSubscription(String address) {
   return subscriptions.get(address);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:4,代码来源:MQTTSessionState.java

示例14: clean

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
void clean() throws Exception {
   for (MqttTopicSubscription mqttTopicSubscription : session.getSessionState().getSubscriptions()) {
      removeSubscription(mqttTopicSubscription.topicName());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:6,代码来源:MQTTSubscriptionManager.java

示例15: persistMessagesForDisconnectedPersistantSession

import io.netty.handler.codec.mqtt.MqttTopicSubscription; //导入依赖的package包/类
@Test
public void persistMessagesForDisconnectedPersistantSession() throws Exception {
	String clientId = TestUtil.newClientId();

	ConnectOptions options = new ConnectOptions();
	options.clientId(clientId);
	options.cleanSession(false);

	String topicName = "testTopic";
	String message = "test message";

	MqttClient client = new MqttClient("mqtt://localhost:" + Settings.INSTANCE.mqttPort());
	client.connectOptions(options).connect();

	client.subscribe(new MqttTopicSubscription(topicName, MqttQoS.EXACTLY_ONCE));
	client.disconnect(true);

	Thread.sleep(100);

	Assert.assertNotNull(Session.NEXUS.get(clientId));

	String publisherId = TestUtil.newClientId();

	MqttClient publisher = new MqttClient("mqtt://localhost:" + Settings.INSTANCE.mqttPort());

	ConnectOptions pubOptions = new ConnectOptions();
	pubOptions.clientId(publisherId);
	pubOptions.cleanSession(true);

	int messageId = 1;
	publisher.connectOptions(pubOptions).connect();
	publisher.publish(new Message(messageId, topicName, publisherId, message.getBytes(CharsetUtil.UTF_8),
			MqttQoS.EXACTLY_ONCE, false));

	Thread.sleep(100);

	publisher.disconnect(true);

	Thread.sleep(1000);

	Assert.assertNull(Session.NEXUS.get(publisherId));

	Topic topic = Topic.NEXUS.get(topicName);
	Assert.assertNotNull(topic);

	OutboundMessageStatus status = OutboundMessageStatus.NEXUS.getBy(messageId, clientId);

	Assert.assertNotNull(status);
	Assert.assertTrue(Messages.key(publisherId, messageId).equals(status.messageKey()));
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:51,代码来源:TopicTest.java


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