1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.river.discovery; 20 21 import java.io.IOException; 22 import java.util.Arrays; 23 import net.jini.core.lookup.ServiceID; 24 import net.jini.io.UnsupportedConstraintException; 25 26 /** 27 * Class representing the values in a multicast request. 28 * 29 * @author Sun Microsystems, Inc. 30 * @since 2.0 31 */ 32 public class MulticastRequest { 33 34 /** The client host. */ 35 private final String host; 36 /** The client listen port. */ 37 private final int port; 38 /** The groups of interest. */ 39 private final String[] groups; 40 /** The IDs of known lookup services. */ 41 private final ServiceID[] serviceIDs; 42 43 /** 44 * Creates a new <code>MulticastRequest</code> instance containing the 45 * given values. Arrays are copied; <code>null</code> array values are 46 * considered equivalent to empty arrays. 47 * 48 * @param host the client host 49 * @param port the client listen port 50 * @param groups the groups of interest 51 * @param serviceIDs the IDs of known lookup services 52 * @throws NullPointerException if <code>host</code> is <code>null</code>, 53 * or if <code>groups</code> or <code>serviceIDs</code> contains 54 * <code>null</code> 55 * @throws IllegalArgumentException if <code>port</code> is out of range 56 */ 57 public MulticastRequest(String host, 58 int port, 59 String[] groups, 60 ServiceID[] serviceIDs) 61 { 62 groups = (groups != null) ? (String[]) groups.clone() : new String[0]; 63 serviceIDs = (serviceIDs != null) ? 64 (ServiceID[]) serviceIDs.clone() : new ServiceID[0]; 65 if (host == null || 66 Arrays.asList(groups).contains(null) || 67 Arrays.asList(serviceIDs).contains(null)) 68 { 69 throw new NullPointerException(); 70 } 71 if (port < 0 || port > 0xFFFF) { 72 throw new IllegalArgumentException("port out of range: " + port); 73 } 74 this.host = host; 75 this.port = port; 76 this.groups = groups; 77 this.serviceIDs = serviceIDs; 78 } 79 80 /** 81 * Returns the client host name. 82 * 83 * @return the client host name 84 */ 85 public String getHost() { 86 return host; 87 } 88 89 /** 90 * Returns the client listen port. 91 * 92 * @return the client listen port 93 */ 94 public int getPort() { 95 return port; 96 } 97 98 /** 99 * Returns the groups targeted by the request. 100 * 101 * @return the groups targeted by the request 102 */ 103 public String[] getGroups() { 104 return (String[]) groups.clone(); 105 } 106 107 /** 108 * Returns the service IDs of known lookup services. 109 * 110 * @return the service IDs of known lookup services 111 */ 112 public ServiceID[] getServiceIDs() { 113 return (ServiceID[]) serviceIDs.clone(); 114 } 115 116 /** 117 * Checks if the constraints whose checking was delayed when this instance 118 * was decoded, if any, are satisfied. If the instance was not decoded, but 119 * directly constructed, this method does nothing. 120 * @throws UnsupportedConstraintException if unable to satisfy the specified 121 * constraints 122 * @throws SecurityException if the given constraints cannot be satisfied 123 * due to insufficient caller permissions, or if the client subject check 124 * fails 125 * @throws IOException if an error occurs in interpreting the data 126 * 127 */ 128 public void checkConstraints() throws IOException { 129 // do nothing 130 } 131 132 /** 133 * Returns string representation of this request. 134 * 135 * @return string representation of this request 136 */ 137 public String toString() { 138 return "MulticastRequest[" + host + ":" + port + ", " + 139 Arrays.asList(groups) + ", " + Arrays.asList(serviceIDs) + "]"; 140 } 141 }