// Bits that deal with connections attaching/detaching from the session
//
/////////////////////////////////////////////////////////////////////
public void attach() {
queue.assertExecuting();
final MqttProtocolHandler h = handler;
clean_session = h.connect_message.cleanSession();
security_context = h.security_context;
h.command_handler = new UnitFn1<Object>() {
@Override
public void call(Object v1) {
on_transport_command(v1);
}
};
destination_parser = h.destination_parser();
mqtt_consumer().consumer_sink.downstream_$eq(Scala2Java.some(h.sink_manager.open()));
final Task ack_connect = new Task() {
@Override
public void run() {
queue.assertExecuting();
connect_message = h.connect_message;
CONNACK connack = new CONNACK();
connack.code(CONNACK.Code.CONNECTION_ACCEPTED);
send(connack);
}
};
if (!clean_session) {
// Setup the previous subscriptions..
session_state.strategy.create(host().store(), client_id);
if (!session_state.subscriptions.isEmpty()) {
h._suspend_read("subscribing");
ArrayList<Topic> topics = Scala2Java.map(session_state.subscriptions.values(), new Fn1<Tuple2<Topic, BindAddress>, Topic>() {
@Override
public Topic apply(Tuple2<Topic, BindAddress> v1) {
return v1._1();
}
});
subscribe(topics, new Task() {
@Override
public void run() {
h.resume_read();
h.queue().execute(ack_connect);
}
});
} else {
ack_connect.run();
}