<commit_before>/**
 * Copyright (c) 2008 Intalio inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intalio inc. - initial API and implementation
 */
package org.intalio.tempo.deployment.utils;

import java.util.Timer;
import java.util.TimerTask;

import org.intalio.tempo.deployment.spi.ComponentManager;
import org.intalio.tempo.deployment.spi.DeploymentServiceCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class to lookup DeploymentService.
 */
public class DeploymentServiceRegister {
    private static final Logger LOG = LoggerFactory.getLogger(DeploymentServiceRegister.class);

    private Timer _timer;
    private DeploymentServiceLookup _lookup;
    private ComponentManager _manager;

    public DeploymentServiceRegister(ComponentManager manager) {
        _manager = manager;
    }
    
    public String getName() {
        return _manager.getComponentManagerName();
    }
    
    public void init() {
        _lookup = new DeploymentServiceLookup();
        _lookup.loadProperties();
        _timer = new Timer("DeploymentServiceRegister Timer for "+getName(), true);
        _timer.schedule(new InitTask(), 1000, 1000);
    }
    
    public void destroy() {
        try {
            DeploymentServiceCallback callback = _lookup.lookupDeploymentCallback();
            if (callback != null) callback.unavailable(_manager);
        } catch (Exception exception) {
            LOG.debug("DeploymentServiceCallback not available during shutdown of "+getName());
            return;
        }
    }
    
    class InitTask extends TimerTask {
        public void run() {
            try {
                DeploymentServiceCallback callback = _lookup.lookupDeploymentCallback();
                LOG.debug("DeploymentServiceCallback: " + callback.getClass());
                if (callback == null) throw new RuntimeException("DeploymentServiceCallback not yet available");
                callback.available(_manager);
                _timer.cancel();
                LOG.debug("Registered ComponentManager: "+getName());
            } catch (Exception e) {
                LOG.debug("DeploymentServiceCallback not yet available (ComponentManager="+getName()+"): " + e.toString(), e);<commit_msg>Remove log statement<commit_after>/**
 * Copyright (c) 2008 Intalio inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intalio inc. - initial API and implementation
 */
package org.intalio.tempo.deployment.utils;

import java.util.Timer;
import java.util.TimerTask;

import org.intalio.tempo.deployment.spi.ComponentManager;
import org.intalio.tempo.deployment.spi.DeploymentServiceCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class to lookup DeploymentService.
 */
public class DeploymentServiceRegister {
    private static final Logger LOG = LoggerFactory.getLogger(DeploymentServiceRegister.class);

    private Timer _timer;
    private DeploymentServiceLookup _lookup;
    private ComponentManager _manager;

    public DeploymentServiceRegister(ComponentManager manager) {
        _manager = manager;
    }
    
    public String getName() {
        return _manager.getComponentManagerName();
    }
    
    public void init() {
        _lookup = new DeploymentServiceLookup();
        _lookup.loadProperties();
        _timer = new Timer("DeploymentServiceRegister Timer for "+getName(), true);
        _timer.schedule(new InitTask(), 1000, 1000);
    }
    
    public void destroy() {
        try {
            DeploymentServiceCallback callback = _lookup.lookupDeploymentCallback();
            if (callback != null) callback.unavailable(_manager);
        } catch (Exception exception) {
            LOG.debug("DeploymentServiceCallback not available during shutdown of "+getName());
            return;
        }
    }
    
    class InitTask extends TimerTask {
        public void run() {
            try {
                DeploymentServiceCallback callback = _lookup.lookupDeploymentCallback();
                if (callback == null) throw new RuntimeException("DeploymentServiceCallback not yet available");
                callback.available(_manager);
                _timer.cancel();
                LOG.debug("Registered ComponentManager: "+getName());
            } catch (Exception e) {
                LOG.debug("DeploymentServiceCallback not yet available (ComponentManager="+getName()+"): " + e.toString(), e);
{'fraction_non_alphanumeric': 0.09258879080270992, 'fraction_numerical': 0.00739067953192363, 'mean_word_length': 2.9967186218211648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699360', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1200, 'n_words': 333}