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


Java IMqttClient类代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.IMqttClient的典型用法代码示例。如果您正苦于以下问题:Java IMqttClient类的具体用法?Java IMqttClient怎么用?Java IMqttClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: closeMqttClientQuite

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * close iMqttClient quietly.
 * @param iMqttClient mqtt client interface.
 */
public static void closeMqttClientQuite(IMqttClient iMqttClient) {
    if (iMqttClient != null) {
        try {
            iMqttClient.disconnectForcibly();
        } catch (MqttException e) {
            logger.info("Close Mqtt Client quite.", e);
        }
    }
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:14,代码来源:IOUtils.java

示例2: getClient

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
private IMqttClient getClient() {
    if (this.client == null) {
        this.createClient();
    } else if (!this.client.isConnected()) {
        try {
            this.client.connect(this.getConnectOptions());
        } catch (MqttException e) {
            LOG.error("Exception ({}) caught in getClient: {}", e.getClass().getName(), e.getMessage(), e);
        }
    }

    return this.client;
}
 
开发者ID:xhibit,项目名称:Teletask-api,代码行数:14,代码来源:MqttPublisher.java

示例3: connect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
private void connect(IMqttClient mqttClient) {
    MqttConnectOptions connOpts = this.getConnectOptions();
    LOG.debug("Connecting to broker");
    try {
        mqttClient.connect(connOpts);
    } catch (MqttException e) {
        LOG.error("Exception ({}) caught in connect: {}", e.getClass().getName(), e.getMessage(), e);
    }
    LOG.debug("Mqtt Client Connected");
}
 
开发者ID:xhibit,项目名称:Teletask-api,代码行数:11,代码来源:MqttPublisher.java

示例4: disconnectAndCloseClient

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @param client
 * @throws MqttException
 */
public static void disconnectAndCloseClient(IMqttClient client) throws MqttException {
  if (client != null) {
    if (client.isConnected()) {
      client.disconnect(0);
    }
    client.close();
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:13,代码来源:Utility.java

示例5: MqttV3Receiver

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @param mqttClient
 * @param reportStream
 */
public MqttV3Receiver(IMqttClient mqttClient, PrintStream reportStream) {
  String methodName = Utility.getMethodName();
  log.entering(className, methodName);

  this.reportStream = reportStream;
  connected = true;

  clientId = mqttClient.getClientId();

  log.exiting(className, methodName);
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:16,代码来源:MqttV3Receiver.java

示例6: testConnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * Tests that a client can be constructed and that it can connect to and disconnect from the
 * service
 * @throws Exception 
 */
@Test
public void testConnect() throws Exception {
  final String methodName = Utility.getMethodName();
  LoggingUtilities.banner(log, cclass, methodName);
  log.entering(className, methodName);

  IMqttClient mqttClient = null;
  try {
    mqttClient = clientFactory.createMqttClient(serverURI, methodName);
    log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
    mqttClient.connect();
    log.info("Disconnecting...");
    mqttClient.disconnect();
    log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
    mqttClient.connect();
    log.info("Disconnecting...");
    mqttClient.disconnect();
  }
  catch (Exception exception) {
    log.log(Level.SEVERE, "caught exception:", exception);
    Assert.fail("Failed:" + methodName + " exception=" + exception);
  }
  finally {
    if (mqttClient != null) {
  	log.info("Close...");
      mqttClient.close();
    }
  }

  log.exiting(className, methodName);
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:37,代码来源:SendReceiveTest.java

示例7: ConnectionManager

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @param context
 * @param eventService
 */
public ConnectionManager(BundleContext context, IEventService eventService) {
	this.eventService = eventService;
	this.registrations = new Registrations();
	this.connections = new ConcurrentHashMap<Connection, IMqttClient>();
	context.registerService(IConnectionManager.class.getName(), this, null);
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:11,代码来源:ConnectionManager.java

示例8: connect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
@Override
public void connect(Connection connection) {
	try {
		IMqttClient client = doConnect(connection);
		connections.put(connection, client);
	}
	catch (Exception e) {
		throw new PahoException(e);
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:11,代码来源:ConnectionManager.java

示例9: disconnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
@Override
public void disconnect(Connection connection) {
	try {
		IMqttClient client = connections.remove(connection);
		if (client != null && client.isConnected()) {
			client.disconnect();
		}
	}
	catch (Exception e) {
		throw new PahoException(e);
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:13,代码来源:ConnectionManager.java

示例10: stop

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * Stop
 */
public void stop() {
	registrations.unregister();
	for (IMqttClient client : connections.values()) {
		try {
			if (client.isConnected()) {
				client.disconnect();
			}
		}
		catch (MqttException e) {
			throw new PahoException(e);
		}
	}
	connections.clear();
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:18,代码来源:ConnectionManager.java

示例11: testConnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @throws Exception 
 */
public void testConnect() throws Exception {

  IMqttClient client = null;
  try {
    String clientId = "testConnect";

    client = new MqttClient(serverURI, clientId);
    System.out.println("Connecting...(serverURI:" + serverURI + ", ClientId:" + clientId);
    client.connect();

    String clientId2 = client.getClientId();
    System.out.println("clientId = " + clientId2);

    boolean isConnected = client.isConnected();
    System.out.println("isConnected = " + isConnected);

    String id = client.getServerURI();
    System.out.println("ServerURI = " + id);

    client.disconnect();
    System.out.println("Disconnecting...");

    client.connect();
    System.out.println("Re-Connecting...");

    client.disconnect();
    System.out.println("Disconnecting...");
  }
  catch (MqttException exception) {
    System.out.println("Unexpected exception: " + exception);
  }
  finally {
    if (client != null) {
  	System.out.println("Close...");
      client.close();
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:42,代码来源:BasicSyncTestCaseMIDP.java

示例12: testHAConnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @throws Exception 
 */
public void testHAConnect() throws Exception {

  IMqttClient client = null;
  try {
    try {
  	String clientId = "testHAConnect";

      // If a proxy client does not support the URI list in the connect options, then this test should fail.
      // We ensure this happens by using a junk URI when creating the client. 
      String junk = "tcp://junk:123";
      client = new MqttClient(junk, clientId);

      // The first URI has a good protocol, but has a garbage hostname. 
      // This ensures that a connect is attempted to the the second URI in the list 
      String[] urls = new String[]{"tcp://junk", serverURI.toString()};

      MqttConnectOptions options = new MqttConnectOptions();
      options.setServerURIs(urls);

      System.out.println("Connecting...");
      client.connect(options);

      System.out.println("Disconnecting...");
      client.disconnect();
    }
    catch (Exception e) {
  	System.out.println(e.getClass().getName() + ": " + e.getMessage());
      e.printStackTrace();
      throw e;
    }
  }
  finally {
    if (client != null) {
  	System.out.println("Close...");
      client.close();
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:42,代码来源:BasicSyncTestCaseMIDP.java

示例13: getClient

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
public IMqttClient getClient() {
	return client;
}
 
开发者ID:Albertus82,项目名称:RouterLogger,代码行数:4,代码来源:BaseMqttClient.java

示例14: testConnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @throws Exception 
 */
@Test
public void testConnect() throws Exception {
  String methodName = Utility.getMethodName();
  LoggingUtilities.banner(log, cclass, methodName);

  IMqttClient client = null;
  try {
    String clientId = methodName;
    client = clientFactory.createMqttClient(serverURI, clientId);

    log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + clientId);
    client.connect();

    String clientId2 = client.getClientId();
    log.info("clientId = " + clientId2);

    boolean isConnected = client.isConnected();
    log.info("isConnected = " + isConnected);

    String id = client.getServerURI();
    log.info("ServerURI = " + id);

    log.info("Disconnecting...");
    client.disconnect();

    log.info("Re-Connecting...");
    client.connect();

    log.info("Disconnecting...");
    client.disconnect();
  }
  catch (MqttException exception) {
    log.log(Level.SEVERE, "caught exception:", exception);
    Assert.fail("Unexpected exception: " + exception);
  }
  finally {
    if (client != null) {
      log.info("Close...");
      client.close();
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:46,代码来源:BasicTest.java

示例15: testHAConnect

import org.eclipse.paho.client.mqttv3.IMqttClient; //导入依赖的package包/类
/**
 * @throws Exception 
 */
@Test
public void testHAConnect() throws Exception {
  String methodName = Utility.getMethodName();
  LoggingUtilities.banner(log, cclass, methodName);

  // Some old clients do not support the new HA interface on the connect call
  if (clientFactory.isHighAvalabilitySupported() == false) {
    return;
  }

  IMqttClient client = null;
  try {
    try {
      String clientId = methodName;

      // If a client does not support the URI list in the connect options, then this test should fail.
      // We ensure this happens by using a junk URI when creating the client. 
      URI junk = new URI("tcp://junk:123");
      client = clientFactory.createMqttClient(junk, clientId);

      // The first URI has a good protocol, but has a garbage hostname. 
      // This ensures that a connect is attempted to the the second URI in the list 
      String[] urls = new String[]{"tcp://junk", serverURI.toString()};

      MqttConnectOptions options = new MqttConnectOptions();
      options.setServerURIs(urls);

      log.info("Connecting...");
      client.connect(options);

      log.info("Disconnecting...");
      client.disconnect();
    }
    catch (Exception e) {
      // logger.info(e.getClass().getName() + ": " + e.getMessage());
      e.printStackTrace();
      throw e;
    }
  }
  finally {
    if (client != null) {
      log.info("Close...");
      client.close();
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:50,代码来源:BasicTest.java


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