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

com.hazelcast.scheduledexecutor.impl.TaskDefinition Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.scheduledexecutor.impl;

import com.hazelcast.nio.serialization.impl.Versioned;

import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class TaskDefinition implements Versioned {

    public enum Type {

        SINGLE_RUN(0), AT_FIXED_RATE(1);

        private final byte id;

        Type(int status) {
            this.id = (byte) status;
        }

        public byte getId() {
            return id;
        }
    }

    private Type type;
    private String name;
    private Callable command;
    private long initialDelay;
    private long period;
    private TimeUnit unit;
    private boolean autoDisposable;

    public TaskDefinition(Type type, String name, Callable command, long delay, TimeUnit unit, boolean autoDisposable) {
        this.type = type;
        this.name = name;
        this.command = command;
        this.initialDelay = delay;
        this.unit = unit;
        this.autoDisposable = autoDisposable;
    }

    public TaskDefinition(Type type, String name, Callable command, long initialDelay, long period,
                          TimeUnit unit, boolean autoDisposable) {
        this.type = type;
        this.name = name;
        this.command = command;
        this.initialDelay = initialDelay;
        this.period = period;
        this.unit = unit;
        this.autoDisposable = autoDisposable;
    }

    public Type getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public Callable getCommand() {
        return command;
    }

    public long getInitialDelay() {
        return initialDelay;
    }

    public long getPeriod() {
        return period;
    }

    public TimeUnit getUnit() {
        return unit;
    }

    public boolean isAutoDisposable() {
        return autoDisposable;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TaskDefinition that = (TaskDefinition) o;
        return initialDelay == that.initialDelay && period == that.period && type == that.type && name.equals(that.name)
                && unit == that.unit && autoDisposable == that.autoDisposable;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(new Object[]{type, name, initialDelay, period, unit, autoDisposable});
    }

    @Override
    public String toString() {
        return "TaskDefinition{"
                + "type=" + type
                + ", name='" + name + '\''
                + ", command=" + command
                + ", initialDelay=" + initialDelay
                + ", period=" + period
                + ", unit=" + unit
                + ", autoDisposable=" + autoDisposable
                + '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy