blob: f2aca58deb6114c4d271e90a947277dc1a573b7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
package org.apache.qpid.client.protocol;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
import java.util.UUID;
import javax.security.sasl.SaslClient;
import org.apache.commons.lang.StringUtils;
import org.apache.mina.common.IdleStatus;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.ConnectionTuneParameters;
import org.apache.qpid.client.handler.ClientMethodDispatcherImpl;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ProtocolInitiation;
import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.transport.Sender;
public class AMQIoTransportProtocolSession extends AMQProtocolSession
{
protected Sender<java.nio.ByteBuffer> _ioSender;
private SaslClient _saslClient;
private ConnectionTuneParameters _connectionTuneParameters;
public AMQIoTransportProtocolSession(AMQProtocolHandler protocolHandler, AMQConnection connection)
{
super(protocolHandler, connection);
}
@Override
public void closeProtocolSession(boolean waitLast) throws AMQException
{
_ioSender.close();
_protocolHandler.getStateManager().changeState(AMQState.CONNECTION_CLOSED);
}
@Override
public void init()
{
_ioSender.send(new ProtocolInitiation(_connection.getProtocolVersion()).toNioByteBuffer());
_ioSender.flush();
}
@Override
protected AMQShortString generateQueueName()
{
int id;
synchronized (_queueIdLock)
{
id = _queueId++;
}
return new AMQShortString("tmp_" + UUID.randomUUID() + "_" + id);
}
@Override
public AMQConnection getAMQConnection()
{
return _connection;
}
@Override
public SaslClient getSaslClient()
{
return _saslClient;
}
@Override
public void setSaslClient(SaslClient client)
{
_saslClient = client;
}
/** @param delay delay in seconds (not ms) */
@Override
void initHeartbeats(int delay)
{
if (delay > 0)
{
// FIXME: actually do something here
HeartbeatDiagnostics.init(delay, HeartbeatConfig.CONFIG.getTimeout(delay));
}
}
@Override
public void methodFrameReceived(final int channel, final AMQMethodBody amqMethodBody) throws AMQException
{
// FIXME?
_protocolHandler.methodBodyReceived(channel, amqMethodBody, null);
}
@Override
public void writeFrame(AMQDataBlock frame, boolean wait)
{
_ioSender.send(frame.toNioByteBuffer());
if (wait)
{
_ioSender.flush();
}
}
@Override
public void setSender(Sender<java.nio.ByteBuffer> sender)
{
_ioSender = sender;
}
@Override
public ConnectionTuneParameters getConnectionTuneParameters()
{
return _connectionTuneParameters;
}
@Override
public void setConnectionTuneParameters(ConnectionTuneParameters params)
{
_connectionTuneParameters = params;
AMQConnection con = getAMQConnection();
con.setMaximumChannelCount(params.getChannelMax());
con.setMaximumFrameSize(params.getFrameMax());
initHeartbeats((int) params.getHeartbeat());
}
}
|