ConnectionBinding.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.network;
22 
23 import java.nio.ByteBuffer;
24 
25 import org.apache.qpid.transport.Binding;
26 import org.apache.qpid.transport.Connection;
27 import org.apache.qpid.transport.ConnectionDelegate;
28 import org.apache.qpid.transport.Receiver;
29 import org.apache.qpid.transport.Sender;
30 
31 /**
32  * ConnectionBinding
33  *
34  */
35 
36 public abstract class ConnectionBinding
37     implements Binding<Connection,ByteBuffer>
38 {
39 
40     public static Binding<Connection,ByteBuffer> get(final Connection connection)
41     {
42         return new ConnectionBinding()
43         {
44             public Connection connection()
45             {
46                 return connection;
47             }
48         };
49     }
50 
51     public static Binding<Connection,ByteBuffer> get(final ConnectionDelegate delegate)
52     {
53         return new ConnectionBinding()
54         {
55             public Connection connection()
56             {
57                 Connection conn = new Connection();
58                 conn.setConnectionDelegate(delegate);
59                 return conn;
60             }
61         };
62     }
63 
64     public static final int MAX_FRAME_SIZE = 64 1024 1;
65 
66     public abstract Connection connection();
67 
68     public Connection endpoint(Sender<ByteBuffer> sender)
69     {
70         Connection conn = connection();
71 
72         // XXX: hardcoded max-frame
73         Disassembler dis = new Disassembler(sender, MAX_FRAME_SIZE);
74         conn.setSender(dis);
75         return conn;
76     }
77 
78     public Receiver<ByteBuffer> receiver(Connection conn)
79     {
80         return new InputHandler(new Assembler(conn));
81     }
82 
83 }