001/*
002 * This file is part of the Kompics component model runtime.
003 *
004 * Copyright (C) 2009 Swedish Institute of Computer Science (SICS) 
005 * Copyright (C) 2009 Royal Institute of Technology (KTH)
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020 */
021package se.sics.kompics.network;
022
023import se.sics.kompics.KompicsEvent;
024
025/**
026 * All subclasses indicate a status change of a connection to the specified {@code peer}.
027 *
028 * @author Lars Kroll {@literal <[email protected]>}
029 */
030public abstract class ConnectionStatus implements KompicsEvent {
031
032    /**
033     * The address of the node the connection relates to.
034     */
035    public final Address peer;
036    /**
037     * The transport protocol of the connection to the {@code peer}.
038     */
039    public final Transport protocol;
040
041    private ConnectionStatus(Address peer, Transport protocol) {
042        this.peer = peer;
043        this.protocol = protocol;
044    }
045
046    public static Requested requested(Address peer, Transport protocol) {
047        return new Requested(peer, protocol);
048    }
049
050    public static Established established(Address peer, Transport protocol) {
051        return new Established(peer, protocol);
052    }
053
054    public static Dropped dropped(Address peer, Transport protocol, boolean last) {
055        return new Dropped(peer, protocol, last);
056    }
057
058    /**
059     * Indicates that a connection to the {@code peer} was requested, for example by sending a message to it.
060     *
061     */
062    public static class Requested extends ConnectionStatus {
063        private Requested(Address peer, Transport protocol) {
064            super(peer, protocol);
065        }
066    }
067
068    /**
069     * Indicates that a connection to the {@code peer} has been established.
070     *
071     */
072    public static class Established extends ConnectionStatus {
073        private Established(Address peer, Transport protocol) {
074            super(peer, protocol);
075        }
076    }
077
078    /**
079     * Indicates that a connection to the {@code peer} was dropped.
080     *
081     */
082    public static class Dropped extends ConnectionStatus {
083
084        /**
085         * Was the last channel to the {@code peer} dropped?
086         * 
087         * If {@code true}, this is definitely equivalent to a session loss event.
088         * 
089         * If {@code false}, it may just be the case that a duplicate channel was closed, which does not incur message
090         * losses, and should thus not be treated as a session loss event.
091         * 
092         */
093        public final boolean last;
094
095        private Dropped(Address peer, Transport protocol, boolean last) {
096            super(peer, protocol);
097            this.last = last;
098        }
099    }
100}