All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.mhus.lib.core.MTimerTask Maven / Gradle / Ivy

There is a newer version: 6.3.1
Show newest version
/*
 *  Copyright (C) 2002-2004 Mike Hummel
 *
 *  This library is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published
 *  by the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package de.mhus.lib.core;

import java.util.Observable;
import java.util.Observer;
import java.util.TimerTask;

import de.mhus.lib.basics.Named;

/**
 * 

Abstract MTimerTask class.

* * @author mikehummel * @version $Id: $Id */ public abstract class MTimerTask extends TimerTask implements Observer, Named { private boolean canceled = false; private String name; /** *

Constructor for MTimerTask.

*/ public MTimerTask() { setName(MSystem.getClassName(this)); } /** {@inheritDoc} */ @Override final public void run() { boolean error = false; try { doit(); } catch (Throwable t) { try { onError(t); } catch (Throwable t1) { } error = true; } try { onFinal(error); } catch (Throwable t) { } } /** *

onError.

* * @param t a {@link java.lang.Throwable} object. */ protected void onError(Throwable t) { t.printStackTrace(); } /** *

onFinal.

* * @param isError a boolean. */ protected void onFinal(boolean isError) { } /** *

doit.

* * @throws java.lang.Exception if any. */ public abstract void doit() throws Exception; /** {@inheritDoc} */ @Override public void update(Observable o, Object arg) { run(); } /** {@inheritDoc} */ @Override public boolean cancel() { setCanceled(true); return super.cancel(); } /** *

isCanceled.

* * @return a boolean. * @since 3.2.9 */ public boolean isCanceled() { return canceled; } /** *

Setter for the field canceled.

* * @param canceled a boolean. * @since 3.2.9 */ public void setCanceled(boolean canceled) { this.canceled = canceled; } /** {@inheritDoc} */ @Override public String getName() { return name; } /** *

Setter for the field name.

* * @param name a {@link java.lang.String} object. * @since 3.2.9 */ public void setName(String name) { this.name = name; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy