private EntityTimeManager(XMPPConnection connection) { super(connection); if (autoEnable) enable(); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { if (enabled) { return Time.createResponse(iqRequest); } else { return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable)); } } }); }
public synchronized void enable() { if (enabled) return; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); sdm.addFeature(Time.NAMESPACE); enabled = true; }
public synchronized void disable() { if (!enabled) return; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); sdm.removeFeature(Time.NAMESPACE); enabled = false; }
public Time getTime(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException { if (!isTimeSupported(jid)) return null; Time request = new Time(); Time response = (Time) connection().createPacketCollectorAndSend(request).nextResultOrThrow(); return response; }
public boolean isTimeSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Time.NAMESPACE); }
public TimeProvider() { super(Time.class); }