/** * ************************************************************************ * DOFDomain.StateListener implementation * ************************************************************************ */ @Override public void stateChanged(DOFDomain domain, State state) { if (state.isConnected()) { synchronized (domainFound) { domainFound.set(true); domainFound.notifyAll(); log.debug(domain.toString() + " became available"); } } }
void getSystemAndStartQuery() { try { Authentication groupId = DOFObjectID.Authentication.create(providerId.getBase()); DOFObjectID.Attribute attr = providerId.getAttribute(DOFObjectID.Attribute.GROUP); Domain domainId = DOFObjectID.Domain.create(attr.getValueObjectID()); DOFCredentials domainCredentials = DOFCredentials.create(hubProvideFactory.coreCredentials, domainId); // // @formatter:off DOFSystem.Config domainSystemConfig = new DOFSystem.Config.Builder() .setName(groupId.getDataString() + "." + domainId.getDataString() + "-DOFSystem") .setCredentials(domainCredentials) .setPermissionsExtendAllowed(true) .setTunnelDomains(true) .build(); // @formatter:on DOFDomain.Config domainConfig = new DOFDomain.Config.Builder(domainCredentials).build(); DOFDomain serviceDomain = hubProvideFactory.dof.createDomain(domainConfig); serviceDomain.addStateListener(this); long t0 = System.currentTimeMillis(); long to = hubProvideFactory.commTimeout; synchronized (domainFound) { while (!domainFound.get()) { try { domainFound.wait(to); if (domainFound.get()) break; long delta = System.currentTimeMillis() - t0; if (delta >= hubProvideFactory.commTimeout) throw new TimeoutException( "timed out: " + to + " waiting for Domain listener to report completed"); to = hubProvideFactory.commTimeout - delta; // spurious wakeup, or wait(to) slightly off System.currentTimeMillis } finally { serviceDomain.removeStateListener(this); } } } DOFSystem system = hubProvideFactory.dof.createSystem(domainSystemConfig, hubProvideFactory.commTimeout); systemData = new CreateSystemTask.SystemData(groupId, domainId, domainCredentials, system); } catch (InterruptedException e) { hubProvideFactory.removeHubRequestMonitor(providerId); log.debug("Create system task interrupted."); return; } catch (Exception e) { hubProvideFactory.removeHubRequestMonitor(providerId); log.debug("Create system failed {} - " + e.getCause(), providerId); return; } synchronized (this) { if (activateInterestOperation == null || activateInterestOperation.isComplete()) activateInterestOperation = systemData.system.beginInterest( systemData.groupId, HubRequestInterface.IID, DOFInterestLevel.ACTIVATE, DOF.TIMEOUT_NEVER, null, null); if (queryOperation == null || queryOperation.isComplete()) { DOFQuery query = new DOFQuery.Builder() .addFilter(providerId) .addRestriction(HubRequestInterface.IID) .build(); queryOperation = systemData.system.beginQuery(query, DOF.TIMEOUT_NEVER, this, null); } createSystemFuture = null; log.debug( "HubManager dof: " + hubProvideFactory.dof.getState().getName() + " beginQuery for: " + providerId.toStandardString() + ":" + HubRequestInterface.IID); } }