All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.remotingjmx.protocol.Versions Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

The newest version!
/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2023 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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.jboss.remotingjmx.protocol;

import static org.jboss.remotingjmx.Constants.EXCLUDED_VERSIONS;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;

import javax.management.remote.JMXServiceURL;

import org.jboss.logging.Logger;
import org.jboss.remoting3.Channel;
import org.jboss.remotingjmx.Capability;
import org.jboss.remotingjmx.MBeanServerManager;
import org.jboss.remotingjmx.ServerMessageInterceptor;
import org.jboss.remotingjmx.VersionedConnection;
import org.jboss.remotingjmx.protocol.v1.VersionOne;
import org.jboss.remotingjmx.protocol.v2.VersionTwo;

/**
 * Single access point to locate the supported versions.
 * 

* As the client and server are written in parallel this makes no distinction between clients and servers when listing the * supported versions. * * @author Darran Lofthouse */ public class Versions { private static final Logger log = Logger.getLogger(Versions.class); private final Map environment; private final Map> supportedVersions; public Versions(final Map environment) { this.environment = environment; Map> supportedVersions = new HashMap>(); supportedVersions.put(VersionOne.getVersionIdentifier(), VersionOne.getCapabilites()); supportedVersions.put(VersionTwo.getVersionIdentifier(), VersionTwo.getCapabilities()); for (Byte current : getExcludedVersions()) { supportedVersions.remove(current); } this.supportedVersions = Collections.unmodifiableMap(supportedVersions); } private Set getExcludedVersions() { Set excluded = new HashSet(); Object list; if (environment != null && environment.containsKey(EXCLUDED_VERSIONS) && (list = environment.get(EXCLUDED_VERSIONS)) != null) { if (list instanceof String) { split((String) list, excluded); } else { log.warnf("Ignoring excluded versions list of type '%s'", list.getClass().getName()); } } split(System.getProperty(EXCLUDED_VERSIONS, ""), excluded); return excluded; } private void split(final String from, final Set to) { String[] values = from.split(","); for (String current : values) { try { String temp = current.trim(); if (temp.length() > 0) { to.add(Byte.valueOf(current.trim())); } } catch (NumberFormatException e) { log.warnf("Unrecognised version '%s' in list.", current); } } } public Set getSupportedVersions(Capability... capabilities) { if (capabilities.length > 0) { Set filteredSupported = new HashSet(supportedVersions.keySet()); for (Byte current : supportedVersions.keySet()) { Set currentCapabilities = supportedVersions.get(current); for (Capability toCheck : capabilities) { if (currentCapabilities.contains(toCheck) == false) { filteredSupported.remove(current); continue; } } } return filteredSupported; } return supportedVersions.keySet(); } public VersionedConnection getVersionedConnection(final byte version, final Channel channel, final JMXServiceURL serviceURL) throws IOException { if (supportedVersions.containsKey(version)) { if (version == VersionOne.getVersionIdentifier()) { return VersionOne.getConnection(channel, environment); } else if (version == VersionTwo.getVersionIdentifier()) { return VersionTwo.getConnection(channel, environment, serviceURL); } } else { log.warnf("An attempt has been made to select an unsupported version 0x0%d", version); } throw new IllegalArgumentException("Unsupported protocol version."); } public void startServer(final byte version, final Channel channel, final MBeanServerManager serverManager, final Executor executor, final ServerMessageInterceptor serverMessageInterceptor) throws IOException { if (supportedVersions.containsKey(version)) { if (version == VersionOne.getVersionIdentifier()) { VersionOne.startServer(channel, serverManager.getDefaultMBeanServer(), executor, serverMessageInterceptor); } else if (version == VersionTwo.getVersionIdentifier()) { VersionTwo.startServer(channel, serverManager, executor, serverMessageInterceptor); } return; } else { log.warnf("An attempt has been made to select an unsupported version 0x0%d", version); } throw new IllegalArgumentException("Unsupported protocol version."); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy