org.onlab.util.SharedScheduledExecutors Java Examples

The following examples show how to use org.onlab.util.SharedScheduledExecutors. 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: DhcpManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    IpAssignment ipAssignment;
    Date dateNow = new Date();

    Map<HostId, IpAssignment> ipAssignmentMap = dhcpStore.listAllMapping();
    for (Map.Entry<HostId, IpAssignment> entry: ipAssignmentMap.entrySet()) {
        ipAssignment = entry.getValue();

        long timeLapsed = dateNow.getTime() - ipAssignment.timestamp().getTime();
        if ((ipAssignment.assignmentStatus() != IpAssignment.AssignmentStatus.Option_Expired) &&
                (ipAssignment.leasePeriod() > 0) && (timeLapsed > (ipAssignment.leasePeriodMs()))) {

            Ip4Address ip4Address = dhcpStore.releaseIP(entry.getKey());
            if (ip4Address != null) {
                hostProviderService.removeIpFromHost(entry.getKey(), ipAssignment.ipAddress());
            }
        }
    }
    timeout = SharedScheduledExecutors.newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
}
 
Example #2
Source File: GeneralDeviceProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void startOrReschedulePeriodicCheckupTasks() {
    synchronized (this) {
        if (checkupTask != null) {
            checkupTask.cancel(false);
        }
        checkupTask = SharedScheduledExecutors.getPoolThreadExecutor()
                .scheduleAtFixedRate(
                        this::submitCheckupTasksForAllDevices,
                        1,
                        checkupInterval,
                        TimeUnit.SECONDS);
    }
}
 
Example #3
Source File: OpenFlowControlMessageProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate() {
    providerService = providerRegistry.register(this);

    // listens all OpenFlow device related events
    controller.addListener(listener);

    // listens all OpenFlow control message
    controller.addMessageListener(messageListener);

    executor = SharedScheduledExecutors.getSingleThreadExecutor();

    connectInitialDevices();
    log.info("Started");
}
 
Example #4
Source File: StatsFlowRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    log.info("Start publishing thread");
    collector = new TelemetryCollector();

    result = SharedScheduledExecutors.getSingleThreadExecutor()
                .scheduleAtFixedRate(collector, INITIAL_DELAY,
                    REFRESH_INTERVAL, TIME_UNIT_SECOND, RECOVER_FROM_FAILURE);
}
 
Example #5
Source File: DhcpManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate() {
    // start the dhcp server
    appId = coreService.registerApplication("org.onosproject.dhcp");

    componentConfigService.registerProperties(getClass());
    cfgService.addListener(cfgListener);
    factories.forEach(cfgService::registerConfigFactory);
    cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class));
    hostProviderService = hostProviderRegistry.register(hostProvider);
    packetService.addProcessor(processor, PacketProcessor.director(1));
    requestPackets();
    timeout = SharedScheduledExecutors.newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
    log.info("Started");
}
 
Example #6
Source File: HostMonitor.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the host monitor. Does nothing if the monitor is already running.
 */
void start() {
    synchronized (this) {
        if (timeout == null) {
            timeout = SharedScheduledExecutors.newTimeout(this, 0, TimeUnit.MILLISECONDS);
        }
    }
}
 
Example #7
Source File: HostMonitor.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    monitoredAddresses.forEach(this::probe);

    synchronized (this) {
        this.timeout = SharedScheduledExecutors.newTimeout(this, probeRate, TimeUnit.MILLISECONDS);
    }
}
 
Example #8
Source File: StreamClientImpl.java    From onos with Apache License 2.0 4 votes vote down vote up
private void handlePendingElectionId(BigInteger masterElectionId) {
    synchronized (requestedToBeMaster) {
        if (pendingElectionId == null) {
            // No pending requests.
            return;
        }
        // Cancel any pending task. We'll reschedule if needed.
        if (pendingElectionIdRetryTask != null) {
            // Do not interrupt if running, as this might be executed by the
            // pending task itself.
            pendingElectionIdRetryTask.cancel(false);
            pendingElectionIdRetryTask = null;
        }
        // We implement a deferring mechanism to avoid becoming master when
        // we shouldn't, i.e. when the requested election ID is bigger than
        // the master one on the device, but we don't want to be master.
        // However, we make sure not to defer for more than
        // ARBITRATION_TIMEOUT_SECONDS.
        final boolean timeoutExpired;
        if (pendingElectionIdTimestamp == 0) {
            pendingElectionIdTimestamp = currentTimeMillis();
            timeoutExpired = false;
        } else {
            timeoutExpired = (currentTimeMillis() - pendingElectionIdTimestamp)
                    > ARBITRATION_TIMEOUT_SECONDS * 1000;
        }
        if (timeoutExpired) {
            log.warn("Arbitration timeout expired for {}! " +
                             "Will send pending election ID now...",
                     deviceId);
        }
        if (!timeoutExpired &&
                !requestedToBeMaster.get() && masterElectionId != null &&
                pendingElectionId.compareTo(masterElectionId) > 0) {
            log.info("Deferring sending master arbitration update for {}, master " +
                             "election ID of server ({}) is smaller than " +
                             "requested one ({}), but we do NOT want to be master...",
                     deviceId, masterElectionId, pendingElectionId);
            // Will try again as soon as the master election ID store is
            // updated...
            masterElectionIdStore.setListener(
                    deviceId, p4DeviceId, masterElectionIdListener);
            // ..or in ARBITRATION_RETRY_SECONDS at the latest (if we missed
            // the store event).
            pendingElectionIdRetryTask = SharedScheduledExecutors.newTimeout(
                    () -> handlePendingElectionId(
                            masterElectionIdStore.get(deviceId, p4DeviceId)),
                    ARBITRATION_RETRY_SECONDS, TimeUnit.SECONDS);
        } else {
            // Send now.
            log.info("Setting mastership on {}... " +
                             "master={}, newElectionId={}, " +
                             "masterElectionId={}, sessionOpen={}",
                     deviceId, requestedToBeMaster.get(),
                     pendingElectionId, masterElectionId,
                     streamChannelManager.isOpen());
            // Optimistically set the reported master status, if wrong, it
            // will be updated by the arbitration response. This alleviates
            // race conditions when calling isMaster() right after setting
            // mastership.
            sendMasterArbitrationUpdate(pendingElectionId);
            isMaster.set(requestedToBeMaster.get());
            pendingElectionId = null;
            pendingElectionIdTimestamp = 0;
            // No need to listen for master election ID changes.
            masterElectionIdStore.unsetListener(deviceId, p4DeviceId);
        }
    }
}
 
Example #9
Source File: CoreManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Deactivate
protected void deactivate() {
    cfgService.unregisterProperties(getClass(), false);
    SharedExecutors.shutdown();
    SharedScheduledExecutors.shutdown();
}
 
Example #10
Source File: MainComponent.java    From ngsdn-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * Schedules a task for the future using the executor service managed by
 * this component.
 *
 * @param task task runnable
 * @param delaySeconds delay in seconds
 */
public void scheduleTask(Runnable task, int delaySeconds) {
    SharedScheduledExecutors.newTimeout(
            () -> executorService.execute(task),
            delaySeconds, TimeUnit.SECONDS);
}
 
Example #11
Source File: MainComponent.java    From onos-p4-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * Schedules a task for the future using the executor service managed by
 * this component.
 *
 * @param task task runnable
 * @param delaySeconds delay in seconds
 */
public void scheduleTask(Runnable task, int delaySeconds) {
    SharedScheduledExecutors.newTimeout(
            () -> executorService.execute(task),
            delaySeconds, TimeUnit.SECONDS);
}
 
Example #12
Source File: MainComponent.java    From onos-p4-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * Schedules a task for the future using the executor service managed by
 * this component.
 *
 * @param task task runnable
 * @param delaySeconds delay in seconds
 */
public void scheduleTask(Runnable task, int delaySeconds) {
    SharedScheduledExecutors.newTimeout(
            () -> executorService.execute(task),
            delaySeconds, TimeUnit.SECONDS);
}