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 package org.apache.river.outrigger.proxy; 19 20 import java.lang.reflect.Method; 21 import net.jini.id.Uuid; 22 import net.jini.core.constraint.MethodConstraints; 23 import net.jini.core.constraint.RemoteMethodControl; 24 import org.apache.river.proxy.ConstrainableProxyUtil; 25 import org.apache.river.admin.AdminIterator; 26 27 /** 28 * Constrainable subclass of <code>IteratorProxy</code> 29 */ 30 final class ConstrainableIteratorProxy extends IteratorProxy { 31 /** 32 * Array containing element pairs in which each pair of elements 33 * represents a mapping between two methods having the following 34 * characteristics: 35 * <ul> 36 * <li> the first element in the pair is one of the public, remote 37 * method(s) that may be invoked by the client through 38 * <code>AdminIterator</code>. 39 * <li> the second element in the pair is the method, implemented 40 * in the backend server class, that is ultimately executed in 41 * the server's backend when the client invokes the corresponding 42 * method in this proxy. 43 * </ul> 44 */ 45 private static final Method[] methodMapArray = { 46 ProxyUtil.getMethod(AdminIterator.class, "next", 47 new Class[] {}), 48 ProxyUtil.getMethod(OutriggerAdmin.class, "nextReps", 49 new Class[] {Uuid.class, 50 int.class, 51 Uuid.class}), 52 53 ProxyUtil.getMethod(AdminIterator.class, "delete", 54 new Class[] {}), 55 ProxyUtil.getMethod(OutriggerAdmin.class,"delete", 56 new Class[] {Uuid.class, 57 Uuid.class}), 58 59 ProxyUtil.getMethod(AdminIterator.class, "close", 60 new Class[] {}), 61 ProxyUtil.getMethod(OutriggerAdmin.class,"close", 62 new Class[] {Uuid.class}) 63 }; 64 65 /** 66 * Create a new <code>ConstrainableIteratorProxy</code>. 67 * @param iterationUuid The identity of the iteration this proxy is for. 68 * @param server reference to remote server for the space. 69 * @param fetchSize Number of entries to ask for when it goes to the 70 * server 71 * @param methodConstraints the client method constraints to place on 72 * this proxy (may be <code>null</code>). 73 * @throws NullPointerException if <code>server</code> or 74 * <code>iterationUuid</code> is <code>null</code>. 75 * @throws ClassCastException if <code>server</code> 76 * does not implement <code>RemoteMethodControl</code>. 77 */ 78 ConstrainableIteratorProxy(Uuid iterationUuid, OutriggerAdmin server, 79 int fetchSize, MethodConstraints methodConstraints) 80 { 81 super(iterationUuid, constrainServer(server, methodConstraints), 82 fetchSize); 83 } 84 85 /** 86 * Returns a copy of the given <code>OutriggerAdmin</code> proxy 87 * having the client method constraints that result after 88 * mapping defined by methodMapArray is applied. 89 * @param server The proxy to attach constrains too. 90 * @param constraints The source method constraints. 91 * @throws NullPointerException if <code>server</code> is 92 * <code>null</code>. 93 * @throws ClassCastException if <code>server</code> 94 * does not implement <code>RemoteMethodControl</code>. 95 */ 96 private static OutriggerAdmin constrainServer(OutriggerAdmin server, 97 MethodConstraints constraints) 98 { 99 final MethodConstraints serverRefConstraints 100 = ConstrainableProxyUtil.translateConstraints(constraints, 101 methodMapArray); 102 final RemoteMethodControl constrainedServer = 103 ((RemoteMethodControl)server). 104 setConstraints(serverRefConstraints); 105 106 return (OutriggerAdmin)constrainedServer; 107 } 108 }