Echo.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.transport;
22 
23 import java.io.IOException;
24 import java.nio.ByteBuffer;
25 
26 import org.apache.qpid.transport.network.ConnectionBinding;
27 import org.apache.qpid.transport.network.io.IoAcceptor;
28 
29 
30 /**
31  * Echo
32  *
33  */
34 
35 public class Echo implements SessionListener
36 {
37 
38     public void opened(Session ssn) {}
39 
40     public void message(Session ssn, MessageTransfer xfr)
41     {
42         int id = xfr.getId();
43         ssn.invoke(xfr);
44         ssn.processed(id);
45     }
46 
47     public void exception(Session ssn, SessionException exc)
48     {
49         exc.printStackTrace();
50     }
51 
52     public void closed(Session ssn) {}
53 
54     public static final void main(String[] argsthrows IOException
55     {
56         ConnectionDelegate delegate = new ServerDelegate()
57         {
58             @Override public Session getSession(Connection conn, SessionAttach atc)
59             {
60                 Session ssn = super.getSession(conn, atc);
61                 ssn.setSessionListener(new Echo());
62                 return ssn;
63             }
64         };
65 
66         IoAcceptor ioa = new IoAcceptor
67             ("0.0.0.0"5672, ConnectionBinding.get(delegate));
68         ioa.start();
69     }
70 
71 }