[jboss-cvs] JBossAS SVN: r102254 - in projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding: impl and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 10 20:40:29 EST 2010
Author: david.lloyd at jboss.com
Date: 2010-03-10 20:40:28 -0500 (Wed, 10 Mar 2010)
New Revision: 102254
Added:
projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/InetSocketAddressServiceBindingValueSource.java
Modified:
projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/ServiceBindingManager.java
projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/SimpleServiceBindingValueSourceImpl.java
Log:
SVCBIND-1: Add getInetSocketAddressBinding methods
Copied: projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/InetSocketAddressServiceBindingValueSource.java (from rev 102253, projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/InetAddressServiceBindingValueSource.java)
===================================================================
--- projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/InetSocketAddressServiceBindingValueSource.java (rev 0)
+++ projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/InetSocketAddressServiceBindingValueSource.java 2010-03-11 01:40:28 UTC (rev 102254)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.services.binding;
+
+import java.net.InetSocketAddress;
+
+/**
+ * A {@link org.jboss.services.binding.ServiceBindingValueSource} that returns an InetSocketAddress. Typically used as
+ * a source for a host binding value.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface InetSocketAddressServiceBindingValueSource extends ServiceBindingValueSource
+{
+ /**
+ * Returns the InetSocketAddress to use for the binding value.
+ *
+ * @param binding the binding. Cannot be <code>null</code>
+ * @return an InetSocketAddress to use as the binding value. May return <code>null</code>.
+ */
+ InetSocketAddress getInetSocketAddressServiceBindingValue(ServiceBinding binding);
+}
\ No newline at end of file
Modified: projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/ServiceBindingManager.java
===================================================================
--- projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/ServiceBindingManager.java 2010-03-11 00:07:33 UTC (rev 102253)
+++ projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/ServiceBindingManager.java 2010-03-11 01:40:28 UTC (rev 102254)
@@ -23,6 +23,7 @@
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Set;
@@ -55,7 +56,7 @@
// ----------------------------------------------------------------- Static
/** Enumeration of types of binding requests */
- public enum BindingType { INT, INETADDRESS, STRING, ELEMENT, URL, RESOURCE, GENERIC };
+ public enum BindingType { INT, INETADDRESS, STRING, ELEMENT, URL, RESOURCE, GENERIC, INETSOCKETADDRESS };
/**
* Algorithm for obtaining a {@link ServiceBindingValueSource} given a particular
@@ -79,6 +80,7 @@
{
case INT:
case INETADDRESS:
+ case INETSOCKETADDRESS:
source = new SimpleServiceBindingValueSourceImpl();
break;
case STRING:
@@ -434,6 +436,136 @@
}
/**
+ * Gets the <code>InetSocketAddress</code> binding value for the
+ * <code>ServiceBinding</code> with the given <code>serviceName</code>
+ * and no binding name qualifier.
+ * <p>
+ * This is typically the {@link ServiceBinding#getBindAddress() bind address}.
+ * </p>
+ *
+ * @param serviceName value to match to {@link ServiceBinding#getServiceName()}
+ * to identify the appropriate binding. Cannot be <code>null</code>.
+ *
+ * @throws NoSuchBindingException if a matching ServiceBinding could not be found
+ *
+ * @see InetSocketAddressServiceBindingValueSource
+ */
+ public InetSocketAddress getInetSocketAddressBinding(String serviceName) throws NoSuchBindingException
+ {
+ return getInetSocketAddressBinding(serviceName, null);
+ }
+
+ /**
+ * Gets the <code>InetSocketAddress</code> binding value for the
+ * <code>ServiceBinding</code> with the given <code>serviceName</code>
+ * and <code>bindingName</code> qualifier.
+ * <p>
+ * This is typically the {@link ServiceBinding#getBindAddress() bind address}.
+ * </p>
+ *
+ * @param serviceName value to match to {@link ServiceBinding#getServiceName()}
+ * to identify the appropriate binding. Cannot be <code>null</code>.
+ * @param bindingName value to match to {@link ServiceBinding#getBindingName()}
+ * to identify the appropriate binding. May be <code>null</code>.
+ *
+ * @throws NoSuchBindingException if a matching ServiceBinding could not be found
+ *
+ * @see InetSocketAddressServiceBindingValueSource
+ */
+ public InetSocketAddress getInetSocketAddressBinding(String serviceName, String bindingName) throws NoSuchBindingException
+ {
+ ServiceBinding binding = store.getServiceBinding(serverName, serviceName, bindingName);
+ ServiceBindingValueSource source = getServiceBindingValueSource(binding, BindingType.INETSOCKETADDRESS);
+ if (source instanceof InetSocketAddressServiceBindingValueSource)
+ {
+ return ((InetSocketAddressServiceBindingValueSource) source).getInetSocketAddressServiceBindingValue(binding);
+ }
+ else
+ {
+ return Util.getBindingValue(source, binding, InetSocketAddress.class);
+ }
+ }
+
+ /**
+ * Same as {@link #getInetSocketAddressBinding(String, String)} but, if no matching
+ * service binding is found, creates a new one using the given
+ * <code>hostName</code> and <code>basePort</code>.
+ *
+ * @param serviceName value to match to {@link ServiceBinding#getServiceName()}
+ * to identify the appropriate binding. Cannot be <code>null</code>.
+ * @param bindingName value to match to {@link ServiceBinding#getBindingName()}
+ * to identify the appropriate binding. May be <code>null</code>.
+ * @param hostName Host name to use for new service binding if one is
+ * created.
+ * @param basePort base port to use for the binding; ServiceBindingStore
+ * may adjust this.
+ *
+ * @return the binding value as an <code>InetSocketAddress</code>
+ *
+ * @throws DuplicateServiceException in unlikely event of concurrent attempts
+ * to create same binding with different
+ * binding values
+ *
+ * @throws UnknownHostException if no IP address for the <code>hostName</code> could be found
+ */
+ public InetSocketAddress getInetSocketAddressBinding(String serviceName, String bindingName,
+ String hostName, int basePort) throws UnknownHostException, DuplicateServiceException
+ {
+ return getInetSocketAddressBinding(serviceName, bindingName, hostName, basePort, false, hostName != null);
+ }
+
+ /**
+ * Same as {@link #getInetSocketAddressBinding(String, String)} but, if no matching
+ * service binding is found, creates a new one using the given
+ * <code>hostName</code> and <code>basePort</code>.
+ *
+ * @param serviceName value to match to {@link ServiceBinding#getServiceName()}
+ * to identify the appropriate binding. Cannot be <code>null</code>.
+ * @param bindingName value to match to {@link ServiceBinding#getBindingName()}
+ * to identify the appropriate binding. May be <code>null</code>.
+ * @param hostName Host name to use for new service binding if one is
+ * created.
+ * @param basePort base port to use for the binding; ServiceBindingStore
+ * may adjust this.
+ * @param fixedPort whether runtime @{link ServiceBinding}s created from this
+ * metadata can alter the port value based on the server
+ * on which the binding is running.
+ * @param fixedHostName whether runtime @{link ServiceBinding}s created from
+ * this metadata can alter the hostName value based on
+ * the server on which the binding is running.
+ *
+ * @return the binding value as an <code>InetSocketAddress</code>
+ *
+ * @throws DuplicateServiceException in unlikely event of concurrent attempts
+ * to create same binding with different
+ * binding values
+ *
+ * @throws UnknownHostException if no IP address for the <code>hostName</code> could be found
+ */
+ public InetSocketAddress getInetSocketAddressBinding(String serviceName, String bindingName,
+ String hostName, int basePort, boolean fixedPort, boolean fixedHostName) throws UnknownHostException, DuplicateServiceException
+ {
+ try
+ {
+ return getInetSocketAddressBinding(serviceName, bindingName);
+ }
+ catch (NoSuchBindingException e)
+ {
+ createBindingFromDefaults(serviceName, bindingName, hostName, basePort, fixedPort, fixedHostName);
+
+ try
+ {
+ return getInetSocketAddressBinding(serviceName, bindingName);
+ }
+ catch (NoSuchBindingException e1)
+ {
+ // Shouldn't be possible
+ throw new IllegalStateException("Newly created binding not found", e1);
+ }
+ }
+ }
+
+ /**
* Gets the <code>String</code> binding value for the
* <code>ServiceBinding</code> with the given <code>serviceName</code>
* and no binding name qualifier.
Modified: projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/SimpleServiceBindingValueSourceImpl.java
===================================================================
--- projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/SimpleServiceBindingValueSourceImpl.java 2010-03-11 00:07:33 UTC (rev 102253)
+++ projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/SimpleServiceBindingValueSourceImpl.java 2010-03-11 01:40:28 UTC (rev 102254)
@@ -24,7 +24,9 @@
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import org.jboss.services.binding.InetAddressServiceBindingValueSource;
+import org.jboss.services.binding.InetSocketAddressServiceBindingValueSource;
import org.jboss.services.binding.IntServiceBindingValueSource;
import org.jboss.services.binding.ServiceBinding;
@@ -39,7 +41,8 @@
public class SimpleServiceBindingValueSourceImpl
implements
IntServiceBindingValueSource,
- InetAddressServiceBindingValueSource
+ InetAddressServiceBindingValueSource,
+ InetSocketAddressServiceBindingValueSource
{
/**
@@ -58,6 +61,12 @@
return binding.getBindAddress();
}
+ /** {@inheritDoc} */
+ public InetSocketAddress getInetSocketAddressServiceBindingValue(final ServiceBinding binding)
+ {
+ return new InetSocketAddress(binding.getBindAddress(), binding.getPort());
+ }
+
/**
* @return <code>new Integer(binding.{@link ServiceBinding#getPort() getPort()})</code>
*/
More information about the jboss-cvs-commits
mailing list