001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.mina.example.imagine.step1.server;
021
022import java.io.IOException;
023import java.net.InetSocketAddress;
024
025import org.apache.mina.example.imagine.step1.codec.ImageCodecFactory;
026import org.apache.mina.filter.codec.ProtocolCodecFilter;
027import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
028
029/**
030 * entry point for the server used in the tutorial on protocol codecs
031 *
032 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
033 */
034
035public class ImageServer {
036    public static final int PORT = 33789;
037
038    public static void main(String[] args) throws IOException {
039        
040        // Create a class that handles sessions, incoming and outgoing data
041        ImageServerIoHandler handler = new ImageServerIoHandler();
042        
043        // This socket acceptor will handle incoming connections
044        NioSocketAcceptor acceptor = new NioSocketAcceptor();
045        
046        // add an IoFilter .  This class is responsible for converting the incoming and 
047        // outgoing raw data to ImageRequest and ImageResponse objects
048        acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new ImageCodecFactory(false)));
049        
050        // set this NioSocketAcceptor's handler to the ImageServerHandler
051        acceptor.setHandler(handler);
052        
053        // Bind to the specified address.  This kicks off the listening for 
054        // incoming connections
055        acceptor.bind(new InetSocketAddress(PORT));
056        System.out.println("Step 1 server is listenig at port " + PORT);
057    }
058}