PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/network/src/main/java/org/jboss/as/network/ManagedBinding.java

#
Java | 108 lines | 50 code | 15 blank | 43 comment | 6 complexity | 1818bf31d98c3f90af55f10ec359d66d MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2010, Red Hat Inc., and individual contributors as indicated
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.network;
  23. import java.io.Closeable;
  24. import java.io.IOException;
  25. import java.net.InetSocketAddress;
  26. /**
  27. * A representation of a socket binding. Open ports need to be registered
  28. * using the {@code SocketBindingManager}.
  29. *
  30. * @author Emanuel Muckenhuber
  31. */
  32. public interface ManagedBinding extends Closeable {
  33. /**
  34. * Get the optional socket binding configuration name.
  35. *
  36. * @return the socket binding name, <code>null</code> if not available
  37. */
  38. String getSocketBindingName();
  39. /**
  40. * Get the bind address.
  41. *
  42. * @return the bind address.
  43. */
  44. InetSocketAddress getBindAddress();
  45. /**
  46. * Close and unregister this binding.
  47. *
  48. * @throws IOException if an I/O error occurs
  49. */
  50. void close() throws IOException;
  51. final class Factory {
  52. public static ManagedBinding createSimpleManagedBinding(final String name, final InetSocketAddress socketAddress, final Closeable closeable) {
  53. if (socketAddress == null) {
  54. throw new IllegalArgumentException("socketAddress is null");
  55. }
  56. return new ManagedBinding() {
  57. @Override
  58. public String getSocketBindingName() {
  59. return name;
  60. }
  61. @Override
  62. public InetSocketAddress getBindAddress() {
  63. return socketAddress;
  64. }
  65. @Override
  66. public void close() throws IOException {
  67. if (closeable != null) {
  68. closeable.close();
  69. }
  70. }
  71. };
  72. }
  73. public static ManagedBinding createSimpleManagedBinding(final SocketBinding socketBinding) {
  74. if (socketBinding == null) {
  75. throw new IllegalArgumentException("socketBinding is null");
  76. }
  77. return new ManagedBinding() {
  78. @Override
  79. public String getSocketBindingName() {
  80. return socketBinding.getName();
  81. }
  82. @Override
  83. public InetSocketAddress getBindAddress() {
  84. return socketBinding.getSocketAddress();
  85. }
  86. @Override
  87. public void close() throws IOException {
  88. // no-op
  89. }
  90. };
  91. }
  92. }
  93. }