1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +02:00

SmackReactor/NIO, Java8/Android19, Pretty print XML, FSM connections

This commit adds
- SmackReactor / NIO
- a framework for finite state machine connections
- support for Java 8
- pretty printed XML debug output

It also
- reworks the integration test framework
- raises the minimum Android API level to 19
- introduces XmppNioTcpConnection

Furthermore fixes SMACK-801 (at least partly). Java 8 language
features are available, but not all runtime library methods. For that
we would need to raise the Android API level to 24 or higher.
This commit is contained in:
Florian Schmaus 2019-02-04 08:59:39 +01:00
parent dba12919d0
commit e98d42790a
144 changed files with 8692 additions and 1455 deletions

View file

@ -37,3 +37,8 @@ task printClasspath(dependsOn: assemble) {
println sourceSets.main.runtimeClasspath.asPath
}
}
task printXmppNioTcpConnectionStateGraph(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main 'org.igniterealtime.smack.smackrepl.StateGraph'
}

View file

@ -0,0 +1,109 @@
/**
*
* Copyright 2018 Florian Schmaus
*
* Licensed 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.
*/
package org.igniterealtime.smack.smackrepl;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.compression.XMPPInputOutputStream.FlushMethod;
import org.jivesoftware.smack.debugger.ConsoleDebugger;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smack.tcp.XmppNioTcpConnection;
import org.jxmpp.util.XmppDateTime;
public class Nio {
private static final Logger LOGGER = Logger.getLogger(Nio.class.getName());
public static void main(String[] args) throws SmackException, IOException, XMPPException, InterruptedException {
doNio(args[0], args[1], args[2]);
}
public static void doNio(String username, String password, String service)
throws SmackException, IOException, XMPPException, InterruptedException {
boolean useTls = true;
boolean useCompression = true;
boolean useFullFlush = true;
boolean javaNetDebug = false;
boolean smackDebug = false;
if (useFullFlush) {
XMPPInputOutputStream.setFlushMethod(FlushMethod.FULL_FLUSH);
}
if (javaNetDebug) {
System.setProperty("javax.net.debug", "all");
}
final SecurityMode securityMode;
if (useTls) {
securityMode = SecurityMode.required;
} else {
securityMode = SecurityMode.disabled;
}
final SmackDebuggerFactory smackDebuggerFactory;
if (smackDebug) {
smackDebuggerFactory = ConsoleDebugger.Factory.INSTANCE;
} else {
smackDebuggerFactory = null;
}
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(username, password)
.setXmppDomain(service)
.setDebuggerFactory(smackDebuggerFactory)
.setCompressionEnabled(useCompression)
.setSecurityMode(securityMode)
.build();
XmppNioTcpConnection connection = new XmppNioTcpConnection(configuration);
connection.setReplyTimeout(5 * 60 * 1000);
connection.addConnectionStateMachineListener((event, c) -> {
LOGGER.info("Connection event: " + event);
});
connection.connect();
connection.login();
Message message = new Message("flo@geekplace.eu",
"It is alive! " + XmppDateTime.formatXEP0082Date(new Date()));
connection.sendStanza(message);
Thread.sleep(1000);
connection.disconnect();
XmppNioTcpConnection.Stats connectionStats = connection.getStats();
// CHECKSTYLE:OFF
System.out.println("NIO successfully finished, yeah!\n" + connectionStats);
// CHECKSTYLE:ON
}
}

View file

@ -0,0 +1,44 @@
/**
*
* Copyright 2018 Florian Schmaus
*
* Licensed 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.
*/
package org.igniterealtime.smack.smackrepl;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import org.jivesoftware.smack.fsm.StateDescriptor;
import org.jivesoftware.smack.fsm.StateDescriptorGraph;
import org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex;
import org.jivesoftware.smack.tcp.XmppNioTcpConnection;
public class StateGraph {
@SuppressWarnings("DefaultCharset")
public static void main(String[] args) throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
GraphVertex<StateDescriptor> stateGraph = StateDescriptorGraph.constructStateDescriptorGraph(XmppNioTcpConnection.getBackwardEdgesStateDescriptors());
PrintWriter pw = new PrintWriter(System.out);
boolean breakStateName = args.length == 0;
StateDescriptorGraph.stateDescriptorGraphToDot(Collections.singleton(stateGraph), pw, breakStateName);
pw.flush();
}
}