001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2016-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.net.events;
020
021import java.net.SocketAddress;
022
023import org.jgrapes.core.Channel;
024import org.jgrapes.core.Components;
025import org.jgrapes.io.events.Opened;
026
027/**
028 * Signals that a server has bound to a socket address and
029 * is ready to accept connections.
030 */
031public class Ready extends Opened {
032
033    private final SocketAddress listenAddress;
034
035    /**
036     * Creates a new event.
037     * 
038     * @param socketAddress the socket address
039     */
040    public Ready(SocketAddress socketAddress) {
041        this.listenAddress = socketAddress;
042    }
043
044    /**
045     * The address that the server has bound to.
046     * 
047     * @return the address
048     */
049    public SocketAddress listenAddress() {
050        return listenAddress;
051    }
052
053    /*
054     * (non-Javadoc)
055     * 
056     * @see java.lang.Object#toString()
057     */
058    @Override
059    public String toString() {
060        StringBuilder builder = new StringBuilder();
061        builder.append(Components.objectName(this))
062            .append(" [")
063            .append(listenAddress)
064            .append(", ");
065        if (channels().length > 0) {
066            builder.append("channels=");
067            builder.append(Channel.toString(channels()));
068        }
069        builder.append(']');
070        return builder.toString();
071    }
072}