Project: engagement_test License: BSD Dependencies:
Used by:
None |
engagement_test/src/edu/wpi/hri/ros/testing/looper/NodTimer.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.ros.testing.looper; 00035 00036 import java.sql.Date; 00037 import java.util.Timer; 00038 00039 import ros.ServiceClient; 00040 import ros.pkg.bml_srvs.srv.BMLHead; 00041 00048 public class NodTimer { 00050 private final long nod_time_; 00051 00053 private Timer nod_timer_; 00054 00056 private NodTask nod_task_; 00057 00059 private final ServiceClient<BMLHead.Request, BMLHead.Response, BMLHead> head_srv_; 00060 00069 public NodTimer( 00070 ServiceClient<BMLHead.Request, BMLHead.Response, BMLHead> head_srv, 00071 long nod_time) { 00072 this.nod_time_ = nod_time; 00073 this.head_srv_ = head_srv; 00074 } 00075 00079 public void run() { 00080 // Store the nod time and create a new timer and 00081 // Create a new nod task using the head service client 00082 this.nod_timer_ = new Timer(); 00083 this.nod_task_ = new NodTask(this.head_srv_); 00084 00085 // Grab the current time 00086 long now = System.currentTimeMillis(); 00087 00088 // Create the date associated with the time the first nod 00089 // should occur 00090 Date start_time = new Date(now + this.nod_time_); 00091 00092 // Create the nod timer with the nod task using the nod time 00093 this.nod_timer_.scheduleAtFixedRate(this.nod_task_, start_time, 00094 this.nod_time_); 00095 } 00096 00102 public boolean cancel() { 00103 // Cancel the nod task and the nod timer 00104 this.nod_task_.cancel(); 00105 this.nod_timer_.cancel(); 00106 00107 return true; 00108 } 00109 } |