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

io.atomix.resource.internal.ResourceCommand Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
/*
 * Copyright 2015 the original author or authors.
 *
 * 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 io.atomix.resource.internal;

import io.atomix.catalyst.buffer.BufferInput;
import io.atomix.catalyst.buffer.BufferOutput;
import io.atomix.catalyst.serializer.CatalystSerializable;
import io.atomix.catalyst.serializer.Serializer;
import io.atomix.copycat.Command;

/**
 * Wrapper for resource commands.
 *
 * @author Jordan Halterman
 */
public final class ResourceCommand, U> extends ResourceOperation implements Command {

  public ResourceCommand() {
  }

  public ResourceCommand(T command) {
    super(command);
  }

  @Override
  public CompactionMode compaction() {
    return operation.compaction();
  }

  @Override
  public void writeObject(BufferOutput buffer, Serializer serializer) {
    super.writeObject(buffer, serializer);
  }

  @Override
  public void readObject(BufferInput buffer, Serializer serializer) {
    super.readObject(buffer, serializer);
  }

  @Override
  public String toString() {
    return String.format("%s[command=%s]", getClass().getSimpleName(), operation);
  }

  /**
   * Resource register command.
   */
  public static class Register implements Command, CatalystSerializable {
    private int eventId;

    public Register() {
    }

    public Register(int eventId) {
      this.eventId = eventId;
    }

    /**
     * Returns the event ID.
     *
     * @return The event ID.
     */
    public int event() {
      return eventId;
    }

    @Override
    public CompactionMode compaction() {
      return CompactionMode.QUORUM;
    }

    @Override
    public void writeObject(BufferOutput buffer, Serializer serializer) {
      buffer.writeByte(eventId);
    }

    @Override
    public void readObject(BufferInput buffer, Serializer serializer) {
      eventId = buffer.readByte();
    }
  }

  /**
   * Resource unregister command.
   */
  public static class Unregister implements Command, CatalystSerializable {
    private int eventId;

    public Unregister() {
    }

    public Unregister(int eventId) {
      this.eventId = eventId;
    }

    /**
     * Returns the event ID.
     *
     * @return The event ID.
     */
    public int event() {
      return eventId;
    }

    @Override
    public CompactionMode compaction() {
      return CompactionMode.QUORUM;
    }

    @Override
    public void writeObject(BufferOutput buffer, Serializer serializer) {
      buffer.writeByte(eventId);
    }

    @Override
    public void readObject(BufferInput buffer, Serializer serializer) {
      eventId = buffer.readByte();
    }
  }

  /**
   * Resource delete command.
   */
  public static class Delete implements Command, CatalystSerializable {
    @Override
    public CompactionMode compaction() {
      return CompactionMode.SEQUENTIAL;
    }

    @Override
    public void writeObject(BufferOutput buffer, Serializer serializer) {
    }
    @Override
    public void readObject(BufferInput buffer, Serializer serializer) {
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy