Package org.apache.s4.comm.test

Source Code of org.apache.s4.comm.test.ProcessMonitorTest

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.s4.comm.test;

import org.apache.s4.comm.file.StaticProcessMonitor;
import org.apache.s4.comm.util.ConfigParser.Cluster.ClusterType;
import org.apache.s4.comm.zk.ZkTaskSetup;
import org.apache.s4.comm.zk.ZkTaskManager;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ProcessMonitorTest {
    public static void main(String[] args) throws Exception {
        // testZkProcessMonitor(args);
        testStaticProcessMonitor(args);
        Thread.sleep(10000);
    }

    private static void testStaticProcessMonitor(String[] args) {
        String address = null;
        address = "localhost:2181";
        StaticProcessMonitor monitor = new StaticProcessMonitor(address,
                                                                "taskmanagerTest",
                                                                ClusterType.S4);
        monitor.monitor();
        System.out.println(monitor.getDestinationList());
        System.out.println(monitor.getDestinationMap());
    }

    private static void testZkProcessMonitor(String[] args) {
        System.out.println("Hereh");
        String address = args[0];
        address = "localhost:2181";
        String processName = args[1];
        ZkTaskSetup zkTaskSetup = new ZkTaskSetup(address,
                                                        "/taskmanagerTest",
                                                        ClusterType.S4);
        zkTaskSetup.cleanUp();
        zkTaskSetup.setUpTasks("1.0.0.", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
                                                      ClusterType.S4);
        obj = taskManager.acquireTask(map);
        System.out.println(processName + "taking up task: " + obj);
        File f = new File("c:/" + obj + ".file");
        f.delete();
        while (true) {
            if (f.exists()) {
                break;
            }
            System.out.println(processName + " processing task: " + obj);
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Exiting task:" + obj);
    }
}
TOP

Related Classes of org.apache.s4.comm.test.ProcessMonitorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.