mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Introduce Smack's Modular Connection Architecture
This is a complete redesign of what was previously XmppNioTcpConnection. The new architecture allows to extend an XMPP client to server (c2s) connection with new transport bindings and other extensions.
This commit is contained in:
parent
cec312fe64
commit
cc636fff21
142 changed files with 6819 additions and 4068 deletions
|
@ -10,18 +10,14 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':smack-tcp')
|
||||
compile project(':smack-bosh')
|
||||
compile project(':smack-java7')
|
||||
compile project(':smack-resolver-minidns')
|
||||
compile project(':smack-resolver-minidns-dox')
|
||||
compile project(':smack-extensions')
|
||||
compile project(':smack-experimental')
|
||||
compile project(':smack-legacy')
|
||||
compile project(':smack-integration-test')
|
||||
compile project(':smack-omemo-signal')
|
||||
// Smack's integration test framework (sintest) depends on
|
||||
// smack-java*-full and since we may want to use parts of sinttest
|
||||
// in the REPL, we simply depend sinttest.
|
||||
api project(':smack-integration-test')
|
||||
|
||||
compile "org.scala-lang:scala-library:$scalaVersion"
|
||||
compile "com.lihaoyi:ammonite_$scalaVersion:1.3.2"
|
||||
|
||||
testCompile project(path: ":smack-core", configuration: "testRuntime")
|
||||
}
|
||||
|
||||
|
@ -38,8 +34,3 @@ task printClasspath(dependsOn: assemble) {
|
|||
println sourceSets.main.runtimeClasspath.asPath
|
||||
}
|
||||
}
|
||||
|
||||
task printXmppNioTcpConnectionStateGraph(type: JavaExec) {
|
||||
classpath sourceSets.main.runtimeClasspath
|
||||
main 'org.igniterealtime.smack.smackrepl.StateGraph'
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Florian Schmaus
|
||||
* Copyright 2018-2020 Florian Schmaus
|
||||
*
|
||||
* This file is part of smack-repl.
|
||||
*
|
||||
|
@ -20,20 +20,27 @@
|
|||
*/
|
||||
package org.igniterealtime.smack.smackrepl;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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.c2s.ModularXmppClientToServerConnection;
|
||||
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
|
||||
import org.jivesoftware.smack.compression.CompressionModuleDescriptor;
|
||||
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.jivesoftware.smack.sm.StreamManagementModuleDescriptor;
|
||||
import org.jivesoftware.smack.tcp.XmppTcpTransportModuleDescriptor;
|
||||
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
|
||||
|
@ -48,10 +55,11 @@ public class Nio {
|
|||
public static void doNio(String username, String password, String service)
|
||||
throws SmackException, IOException, XMPPException, InterruptedException {
|
||||
boolean useTls = true;
|
||||
boolean useStreamMangement = false;
|
||||
boolean useCompression = true;
|
||||
boolean useFullFlush = true;
|
||||
boolean javaNetDebug = false;
|
||||
boolean smackDebug = false;
|
||||
boolean smackDebug = true;
|
||||
|
||||
if (useFullFlush) {
|
||||
XMPPInputOutputStream.setFlushMethod(FlushMethod.FULL_FLUSH);
|
||||
|
@ -75,15 +83,29 @@ public class Nio {
|
|||
smackDebuggerFactory = null;
|
||||
}
|
||||
|
||||
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
|
||||
ModularXmppClientToServerConnectionConfiguration.Builder configurationBuilder = ModularXmppClientToServerConnectionConfiguration.builder()
|
||||
.setUsernameAndPassword(username, password)
|
||||
.setXmppDomain(service)
|
||||
.setDebuggerFactory(smackDebuggerFactory)
|
||||
.setCompressionEnabled(useCompression)
|
||||
.setSecurityMode(securityMode)
|
||||
.build();
|
||||
.removeAllModules()
|
||||
.addModule(XmppTcpTransportModuleDescriptor.class);
|
||||
|
||||
XmppNioTcpConnection connection = new XmppNioTcpConnection(configuration);
|
||||
if (useCompression) {
|
||||
configurationBuilder.addModule(CompressionModuleDescriptor.class);
|
||||
configurationBuilder.setCompressionEnabled(true);
|
||||
}
|
||||
if (useStreamMangement) {
|
||||
configurationBuilder.addModule(StreamManagementModuleDescriptor.class);
|
||||
}
|
||||
|
||||
ModularXmppClientToServerConnectionConfiguration configuration = configurationBuilder.build();
|
||||
|
||||
PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)));
|
||||
configuration.printStateGraphInDotFormat(printWriter, false);
|
||||
printWriter.flush();
|
||||
|
||||
ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(configuration);
|
||||
|
||||
connection.setReplyTimeout(5 * 60 * 1000);
|
||||
|
||||
|
@ -105,7 +127,7 @@ public class Nio {
|
|||
|
||||
connection.disconnect();
|
||||
|
||||
XmppNioTcpConnection.Stats connectionStats = connection.getStats();
|
||||
ModularXmppClientToServerConnection.Stats connectionStats = connection.getStats();
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("NIO successfully finished, yeah!\n" + connectionStats);
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Florian Schmaus
|
||||
*
|
||||
* This file is part of smack-repl.
|
||||
*
|
||||
* smack-repl is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue