net.sf.eBusx.io.EFileNotification Maven / Gradle / Ivy
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General
// Public License along with this library; if not, write to the
//
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA
// 02111-1307 USA
//
// The Initial Developer of the Original Code is Charles W. Rapp.
// Portions created by Charles W. Rapp are
// Copyright 2013, 2016. Charles W. Rapp
// All Rights Reserved.
//
package net.sf.eBusx.io;
import java.io.File;
import java.io.Serializable;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.ENotificationMessage;
/**
* Used to transmit a Java {@link java.nio.file.WatchEvent}
* asynchronously to all interested listeners. The message
* subject is the file or directory path. The message contains
* the how the file changed (created, modified, or deleted), the
* file modification timestamp (in Java millisecond epoch time),
* and the file length in byte.
*
* @author Charles Rapp
*/
@EFieldInfo(fields={"file",
"eventType",
"lastModified",
"length"})
public final class EFileNotification
extends ENotificationMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new file notification instance for the given
* parameters.
* @param subject the notification subject.
* @param file the event applies to this file.
* @param eventType {@code file} was either created,
* modified, or deleted.
* @param modifyTime the file modify time. Will be
* {@code null} when {@code eventType} is
* {@link EventType#DELETE}.
* @param length the file length. Will be zero for a delete
* event type.
*/
/* package */ EFileNotification(final String subject,
final File file,
final EventType eventType,
final long modifyTime,
final long length)
{
this (subject,
System.currentTimeMillis(),
file,
eventType,
modifyTime,
length);
} // end of EFileNotification(...)
/**
* Creates a new file notification instance from the
* de-serialized parameters.
* @param subject the notification subject.
* @param timestamp the message timestamp.
* @param file the event applies to this file.
* @param eventType {@code file} was either created,
* modified, or deleted.
* @param modifyTime the file modify time. Will be
* {@code null} when {@code eventType} is
* {@link EventType#DELETE}.
* @param length the file length. Will be zero for a delete
* event type.
*/
public EFileNotification(final String subject,
final long timestamp,
final File file,
final EventType eventType,
final long modifyTime,
final long length)
{
super (subject, timestamp);
this.file = file;
this.eventType = eventType;
this.lastModified = modifyTime;
this.length = length;
} // end of EFileNotification(...)
//
// end of Constructors.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Enums.
//
/**
* The watched file was either created, modified, or deleted.
*/
public enum EventType
{
//-----------------------------------------------------------
// Member methods.
//
/**
* The file was newly created.
*/
CREATE,
/**
* The file was modified.
*/
MODIFY,
/**
* The file event was deleted. The file
* {@link #lastModified last modify timestamp} and
* {@link #length} will be zero.
*/
DELETE
} // end of enum EventType
//---------------------------------------------------------------
// Member data.
//
/**
* The notification applies to this file instance.
*/
public final File file;
/**
* This notification signifies that either the file or
* directory was created, modified, or deleted.
*/
public final EventType eventType;
/**
* The date and time when the {@link #file} was last
* modified. Will be zero if {@link #eventType} is
* {@link EventType#DELETE}.
*/
public final long lastModified;
/**
* {@link #file} length in bytes. Will be zero if
* {@link #eventType} is {@link EventType#DELETE}.
*/
public final long length;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of class EFileNotification
© 2015 - 2025 Weber Informatics LLC | Privacy Policy