mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 10:09:38 +02:00
Create JingleTransportManager framework
This commit is contained in:
parent
05b0e3650e
commit
1775c691af
19 changed files with 315 additions and 48 deletions
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* 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.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||
|
||||
/**
|
||||
* Interface with methods that JingleContentTransportManagers must implement.
|
||||
*/
|
||||
public abstract class AbstractJingleContentTransportManager<D extends JingleContentTransport> extends Manager {
|
||||
|
||||
public AbstractJingleContentTransportManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
JingleTransportManager.getInstanceFor(connection).registerJingleContentTransportManager(this);
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), createJingleContentTransportProvider());
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
|
||||
}
|
||||
|
||||
protected abstract JingleContentTransportProvider<D> createJingleContentTransportProvider();
|
||||
|
||||
public abstract String getNamespace();
|
||||
|
||||
public abstract void acceptInputStream(Jingle jingle, JingleTransportInputStreamCallback callback);
|
||||
|
||||
public abstract OutputStream createOutputStream(Jingle jingle);
|
||||
}
|
|
@ -14,11 +14,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle.provider;
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||
|
||||
public class JingleContentProviderManager {
|
||||
|
||||
private static final Map<String, JingleContentDescriptionProvider<?>> jingleContentDescriptionProviders = new ConcurrentHashMap<>();
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -56,7 +55,6 @@ public final class JingleManager extends Manager {
|
|||
|
||||
private final Map<String, JingleHandler> descriptionHandlers = new ConcurrentHashMap<>();
|
||||
private final Map<FullJidAndSessionId, JingleSession> jingleSessions = new ConcurrentHashMap<>();
|
||||
private final Map<String, JingleContentTransportManager> transportManagers = new HashMap<>();
|
||||
|
||||
private JingleManager(final XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* 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.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
|
||||
|
||||
/**
|
||||
* Manager for JingleContentTransportManagers.
|
||||
*/
|
||||
public final class JingleTransportManager extends Manager {
|
||||
|
||||
public static final WeakHashMap<XMPPConnection, JingleTransportManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private final HashMap<String, AbstractJingleContentTransportManager<?>> contentTransportManagers = new HashMap<>();
|
||||
|
||||
private JingleTransportManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
public static JingleTransportManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleTransportManager manager = INSTANCES.get(connection);
|
||||
if (manager == null) {
|
||||
manager = new JingleTransportManager(connection);
|
||||
INSTANCES.put(connection, manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public AbstractJingleContentTransportManager<?> getJingleContentTransportManager(String namespace) throws UnsupportedJingleTransportException {
|
||||
AbstractJingleContentTransportManager<?> manager = contentTransportManagers.get(namespace);
|
||||
if (manager == null) {
|
||||
throw new UnsupportedJingleTransportException("Cannot find registered JingleContentTransportManager for " + namespace);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public void registerJingleContentTransportManager(AbstractJingleContentTransportManager<?> manager) {
|
||||
contentTransportManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public void unregisterJingleContentTransportManager(AbstractJingleContentTransportManager<?> manager) {
|
||||
contentTransportManagers.remove(manager.getNamespace());
|
||||
}
|
||||
|
||||
public static String generateSessionId() {
|
||||
return StringUtils.randomString(24);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* 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.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
|
|
|
@ -14,18 +14,16 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
package org.jivesoftware.smackx.jingle.exception;
|
||||
|
||||
/**
|
||||
* Interface with methods that JingleContentTransportManagers must implement.
|
||||
* Exception gets thrown when we miss a JingleContentTransportManager for a certain transport namespace.
|
||||
*/
|
||||
public interface JingleContentTransportManager {
|
||||
public class UnsupportedJingleTransportException extends Exception {
|
||||
|
||||
void acceptInputStream(Jingle jingle, JingleTransportInputStreamCallback callback);
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
OutputStream createOutputStream(Jingle jingle);
|
||||
public UnsupportedJingleTransportException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stanzas and Extension Elements for <a href="https://xmpp.org/extensions/xep-0166.html">XEP-0166: Jingle</a>.
|
||||
* Exceptions.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle.exception;
|
|
@ -20,6 +20,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.jingle.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue