001/** 002 * 003 * Copyright 2018 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack; 018 019import java.nio.channels.ClosedChannelException; 020import java.nio.channels.SelectableChannel; 021import java.nio.channels.SelectionKey; 022 023import org.jivesoftware.smack.SmackReactor.ChannelSelectedCallback; 024import org.jivesoftware.smack.fsm.AbstractXmppStateMachineConnection; 025import org.jivesoftware.smack.fsm.StateDescriptor; 026import org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex; 027 028public abstract class AbstractXmppNioConnection extends AbstractXmppStateMachineConnection { 029 030 protected AbstractXmppNioConnection(ConnectionConfiguration configuration, GraphVertex<StateDescriptor> initialStateDescriptorVertex) { 031 super(configuration, initialStateDescriptorVertex); 032 } 033 034 protected SelectionKey registerWithSelector(SelectableChannel channel, int ops, ChannelSelectedCallback callback) 035 throws ClosedChannelException { 036 return SMACK_REACTOR.registerWithSelector(channel, ops, callback); 037 } 038 039 /** 040 * Set the interest Ops of a SelectionKey. Since Java's NIO interestOps(int) can block at any time, we use a queue 041 * to perform the actual operation in the reactor where we can perform this operation non-blocking. 042 * 043 * @param selectionKey 044 * @param interestOps 045 */ 046 protected void setInterestOps(SelectionKey selectionKey, int interestOps) { 047 SMACK_REACTOR.setInterestOps(selectionKey, interestOps); 048 } 049 050 @Override 051 protected void finalize() { 052 disconnect(); 053 } 054}