http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/pom.xml b/libraries/jini/importer/pom.xml deleted file mode 100644 index 4bc0aac..0000000 --- a/libraries/jini/importer/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini-importer</artifactId> - <name>Qi4j Library - Jini Services Importer</name> - - <dependencies> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.api</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.testsupport</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.runtime</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.bootstrap</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.observations</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-core</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-ext</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jsk-lib</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.wonderly</groupId> - <artifactId>startnow</artifactId> - <version>1.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> -</project>
http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniImporter.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniImporter.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniImporter.java deleted file mode 100644 index 5fba734..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniImporter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import org.qi4j.api.common.Optional; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.service.ImportedServiceDescriptor; -import org.qi4j.api.service.ServiceImporter; -import org.qi4j.api.service.ServiceImporterException; - -import java.io.IOException; -import java.lang.reflect.Proxy; - -public class JiniImporter - implements ServiceImporter -{ - @Optional @Service private JiniStatusService statusService; - - /** - * Import a service from Jini by looking creating a Proxy which holds the Lookup cache to the wanted Jini service. - * - * @param serviceDescriptor The service descriptor. - * @return a service instance - * @throws ServiceImporterException - */ - - public Object importService( ImportedServiceDescriptor serviceDescriptor ) - throws ServiceImporterException - { - final Class<?> serviceType = serviceDescriptor.type(); - JiniProxyHandler handler; - try - { - handler = new JiniProxyHandler( serviceType, statusService ); - } - catch( IOException e ) - { - throw new ServiceImporterException( "Unable to establish network.", e ); - } - Class[] type = new Class[]{ serviceType }; - return Proxy.newProxyInstance( JiniImporter.class.getClassLoader(), type, handler ); - } - - public boolean isActive( Object instance ) - { - JiniProxyHandler jiniHandler = (JiniProxyHandler) Proxy.getInvocationHandler( instance ); - return jiniHandler.isActive(); - } - - public boolean isAvailable( Object instance ) - { - JiniProxyHandler jiniHandler = (JiniProxyHandler) Proxy.getInvocationHandler( instance ); - return jiniHandler.isActive(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniProxyHandler.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniProxyHandler.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniProxyHandler.java deleted file mode 100644 index d0cf194..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniProxyHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import net.jini.core.entry.Entry; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceItem; -import net.jini.core.lookup.ServiceTemplate; -import net.jini.discovery.DiscoveryManagement; -import net.jini.lease.LeaseRenewalManager; -import net.jini.lookup.*; -import org.qi4j.api.service.ServiceImporterException; - -import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -public class JiniProxyHandler - implements InvocationHandler, ServiceDiscoveryListener -{ - private JiniStatusService statusService; - private LookupCache lookupCache; - private Object jiniService; - - JiniProxyHandler( Class serviceType, JiniStatusService statusService ) - throws IOException - { - this.statusService = statusService; - LeaseRenewalManager leaseRenewal = null; - DiscoveryManagement discoveryManagement = null; - ServiceDiscoveryManager sdm = new ServiceDiscoveryManager( discoveryManagement, leaseRenewal ); - ServiceItemFilter filter = null; - Entry[] entries = null; // Lookup all, regardless of entries. - ServiceID serviceId = null; // Lookup all, regardless of serviceId. - Class[] type = new Class[]{ serviceType }; - ServiceTemplate template = new ServiceTemplate( serviceId, type, entries ); - lookupCache = sdm.createLookupCache( template, filter, this ); - lookupCache.addListener( this ); - } - - public Object invoke( Object o, Method method, Object[] args ) - throws Throwable - { - synchronized( this ) - { - if( jiniService == null ) - { - ServiceItem item = lookupCache.lookup( null ); - if( item == null ) - { - throw new ServiceImporterException( "Jini service currently not available" ); - } - jiniService = item.service; - - if( jiniService == null ) - { - throw new ServiceImporterException( "Jini service currently not available" ); - } - } - - return method.invoke( jiniService, args ); - } - } - - public synchronized boolean isActive() - { - return jiniService != null; - } - - public void serviceAdded( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - synchronized( this ) - { - ServiceItem item = serviceDiscoveryEvent.getPostEventServiceItem(); - jiniService = item.service; - } - if( statusService != null ) - { - statusService.serviceAdded( serviceDiscoveryEvent ); - } - } - - public void serviceRemoved( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - synchronized( this ) - { - ServiceItem item = serviceDiscoveryEvent.getPostEventServiceItem(); - if( item.service.equals( jiniService ) ) - { - jiniService = null; - } - } - if( statusService != null ) - { - statusService.serviceRemoved( serviceDiscoveryEvent ); - } - } - - public void serviceChanged( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - if( statusService != null ) - { - statusService.serviceChanged( serviceDiscoveryEvent ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniServiceObservation.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniServiceObservation.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniServiceObservation.java deleted file mode 100644 index d03353d..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniServiceObservation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import org.qi4j.api.property.Property; -import org.qi4j.library.observations.Observation; - -public interface JiniServiceObservation extends Observation -{ - Property<String> serviceId(); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatus.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatus.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatus.java deleted file mode 100644 index 57448fa..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatus.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import net.jini.core.lookup.ServiceID; - -public interface JiniStatus -{ - boolean isAvailable( ServiceID service ); - - boolean isAvailable( Class type ); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusMixin.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusMixin.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusMixin.java deleted file mode 100644 index cf0d3b7..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusMixin.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceItem; -import net.jini.lookup.ServiceDiscoveryEvent; -import net.jini.lookup.ServiceDiscoveryListener; -import org.qi4j.api.injection.scope.This; -import org.qi4j.library.observations.Observable; - -import java.util.HashSet; -import java.util.Set; -import java.util.WeakHashMap; - -public class JiniStatusMixin - implements JiniStatus, ServiceDiscoveryListener -{ - @This Observable<JiniServiceObservation> observable; - - private WeakHashMap<ServiceID, Object> serviceIds; - private WeakHashMap<Class, Set<Object>> services; - - public JiniStatusMixin() - { - services = new WeakHashMap<Class, Set<Object>>(); - serviceIds = new WeakHashMap<ServiceID, Object>(); - } - - public boolean isAvailable( ServiceID service ) - { - return serviceIds.containsKey( service ); - } - - public boolean isAvailable( Class type ) - { - return services.containsKey( type ); - } - - public void serviceAdded( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - ServiceItem item = serviceDiscoveryEvent.getPostEventServiceItem(); - Object service = item.service; - Class[] types = item.service.getClass().getClasses(); - ServiceID id = item.serviceID; - serviceIds.put( id, service ); - for( Class type : types ) - { - Set<Object> set = services.get( type ); - if( set == null ) - { - set = new HashSet<Object>(); - services.put( type, set ); - } - set.add( service ); - } - } - - public void serviceRemoved( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - ServiceItem item = serviceDiscoveryEvent.getPreEventServiceItem(); - Object service = item.service; - Class[] types = item.service.getClass().getClasses(); - ServiceID id = item.serviceID; - serviceIds.remove( id ); - for( Class type : types ) - { - Set<Object> set = services.get( type ); - if( set != null ) - { - set.remove( service ); - if( set.size() == 0 ) - { - services.remove( type ); - } - } - } - } - - public void serviceChanged( ServiceDiscoveryEvent serviceDiscoveryEvent ) - { - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusService.java b/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusService.java deleted file mode 100644 index fb8652f..0000000 --- a/libraries/jini/importer/src/main/java/org/qi4j/library/jini/importer/JiniStatusService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import net.jini.lookup.ServiceDiscoveryListener; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceComposite; -import org.qi4j.library.observations.Observable; - -@Mixins( { JiniStatusMixin.class } ) -public interface JiniStatusService - extends JiniStatus, ServiceDiscoveryListener, Observable<JiniServiceObservation>, ServiceComposite -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/ImportExternalJiniServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/ImportExternalJiniServiceTest.java b/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/ImportExternalJiniServiceTest.java deleted file mode 100644 index 37267e4..0000000 --- a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/ImportExternalJiniServiceTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Ignore; -import org.junit.Test; -import org.qi4j.api.service.ServiceFinder; -import org.qi4j.api.service.ServiceReference; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.bootstrap.SingletonAssembler; -import org.qi4j.library.jini.importer.org.qi4j.library.jini.tests.InterpreterService; - -import java.io.IOException; -import java.util.Iterator; - -/** - * This testcase starts an external non-Qi4j, Jini application and then makes sure that such Jini service will appear - * as a Qi4j service via the ServiceImporter mechanism. - */ -public class ImportExternalJiniServiceTest -{ - private Process process; - - @Ignore( "Doesn't seem to work right now" ) - @Test - public void givenExternalJiniServicePresentInitiallyWhenQi4jApplicationStartsExpectServiceToBeImported() - throws IOException, InterruptedException - { - startExternalJiniService(); - - SingletonAssembler assembler = new SingletonAssembler() - { - public void assemble( ModuleAssembly module ) throws AssemblyException - { - module.importedServices( InterpreterService.class ).importedBy( JiniImporter.class ); - } - }; - final ServiceFinder finder = assembler.serviceFinder(); - final Iterable<ServiceReference<InterpreterService>> iterable = finder.findServices( InterpreterService.class ); - final Iterator<ServiceReference<InterpreterService>> iterator = iterable.iterator(); - final String serviceName = InterpreterService.class.getName(); - assertTrue( "Service proxy not found: " + serviceName, iterator.hasNext() ); -// assertTrue( "Service is not active: " + serviceName, iterator.next().isActive() ); - InterpreterService service = iterator.next().get(); - service.push( 123 ); - service.push( 321 ); - service.addition(); - assertEquals( 444, (int) service.popLong() ); - shutdownExternalJiniService(); - } - - private void startExternalJiniService() - throws IOException - { - String[] args = { "org.qi4j.library.jini.tests.Main" }; - process = Runtime.getRuntime().exec( "java", args ); - } - - private void shutdownExternalJiniService() - throws IOException, InterruptedException - { - process.destroy(); - process.waitFor(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/IllegalExpressionException.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/IllegalExpressionException.java b/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/IllegalExpressionException.java deleted file mode 100644 index b1561f2..0000000 --- a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/IllegalExpressionException.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer.org.qi4j.library.jini.tests; - -public class IllegalExpressionException extends RuntimeException -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterService.java b/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterService.java deleted file mode 100644 index d5781ee..0000000 --- a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer.org.qi4j.library.jini.tests; - -public interface InterpreterService -{ - void push( long value ); - - void push( double value ); - - long popLong(); - - double popDouble(); - - void addition(); - - void subtraction(); - - void multiplication(); - - void division(); - - void modulo(); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterServiceImpl.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterServiceImpl.java b/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterServiceImpl.java deleted file mode 100644 index feb710f..0000000 --- a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/InterpreterServiceImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer.org.qi4j.library.jini.tests; - -import net.jini.config.ConfigurationException; -import org.wonderly.jini2.PersistentJiniService; - -import java.io.IOException; -import java.util.Stack; - -public class InterpreterServiceImpl extends PersistentJiniService - implements InterpreterService -{ - private Stack<Entry> stack = new Stack<Entry>(); - - public InterpreterServiceImpl( String[] arguments ) - throws IOException, ConfigurationException - { - super( arguments ); - } - - public void push( long value ) - { - stack.push( new Entry( value ) ); - } - - public void push( double value ) - { - stack.push( new Entry( value ) ); - } - - public long popLong() - { - Entry entry = stack.pop(); - return entry.value.longValue(); - } - - public double popDouble() - { - Entry entry = stack.pop(); - return entry.value.doubleValue(); - } - - public void addition() - { - Entry entry1 = stack.pop(); - Entry entry2 = stack.pop(); - if( entry1.type == EntryType.llong ) - { - if( entry2.type != EntryType.llong ) - { - throw new IllegalExpressionException(); - } - final long result = entry2.value.longValue() + entry1.value.longValue(); - stack.push( new Entry( result ) ); - } - else - { - if( entry2.type != EntryType.ddouble ) - { - throw new IllegalExpressionException(); - } - final double result = entry2.value.doubleValue() + entry1.value.doubleValue(); - stack.push( new Entry( result ) ); - } - } - - public void subtraction() - { - Entry entry1 = stack.pop(); - Entry entry2 = stack.pop(); - if( entry1.type == EntryType.llong ) - { - if( entry2.type != EntryType.llong ) - { - throw new IllegalExpressionException(); - } - final long result = entry2.value.longValue() - entry1.value.longValue(); - stack.push( new Entry( result ) ); - } - else - { - if( entry2.type != EntryType.ddouble ) - { - throw new IllegalExpressionException(); - } - final double result = entry2.value.doubleValue() - entry1.value.doubleValue(); - stack.push( new Entry( result ) ); - } - } - - public void multiplication() - { - Entry entry1 = stack.pop(); - Entry entry2 = stack.pop(); - if( entry1.type == EntryType.llong ) - { - if( entry2.type != EntryType.llong ) - { - throw new IllegalExpressionException(); - } - final long result = entry2.value.longValue() * entry1.value.longValue(); - stack.push( new Entry( result ) ); - } - else - { - if( entry2.type != EntryType.ddouble ) - { - throw new IllegalExpressionException(); - } - final double result = entry2.value.doubleValue() * entry1.value.doubleValue(); - stack.push( new Entry( result ) ); - } - } - - public void division() - { - Entry entry1 = stack.pop(); - Entry entry2 = stack.pop(); - if( entry1.type == EntryType.llong ) - { - if( entry2.type != EntryType.llong ) - { - throw new IllegalExpressionException(); - } - final long result = entry2.value.longValue() / entry1.value.longValue(); - stack.push( new Entry( result ) ); - } - else - { - if( entry2.type != EntryType.ddouble ) - { - throw new IllegalExpressionException(); - } - final double result = entry2.value.doubleValue() / entry1.value.doubleValue(); - stack.push( new Entry( result ) ); - } - } - - public void modulo() - { - Entry entry1 = stack.pop(); - Entry entry2 = stack.pop(); - if( entry1.type == EntryType.llong ) - { - if( entry2.type != EntryType.llong ) - { - throw new IllegalExpressionException(); - } - final long result = entry2.value.longValue() % entry1.value.longValue(); - stack.push( new Entry( result ) ); - } - else - { - throw new IllegalExpressionException(); - } - } - - private class Entry - { - EntryType type; - Number value; - - public Entry( double value ) - { - type = EntryType.ddouble; - this.value = value; - } - - public Entry( long value ) - { - type = EntryType.llong; - this.value = value; - } - } - - private enum EntryType - { - ddouble, llong - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/Main.java ---------------------------------------------------------------------- diff --git a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/Main.java b/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/Main.java deleted file mode 100644 index 10f3840..0000000 --- a/libraries/jini/importer/src/test/java/org/qi4j/library/jini/importer/org/qi4j/library/jini/tests/Main.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.library.jini.importer.org.qi4j.library.jini.tests; - -import java.security.*; - -public class Main -{ - private static InterpreterServiceImpl jiniService; - - public static void main( String[] args ) - throws Exception - { - Policy.setPolicy( new AllPolicy() ); - jiniService = new InterpreterServiceImpl( args ); - jiniService.startService(); - System.out.println( "Started 1!" ); - System.out.println( jiniService.getServiceID() ); - System.out.println( "Started 2!" ); - } - - private static class AllPolicy extends Policy - { - public PermissionCollection getPermissions( CodeSource codeSource ) - { - final AllPermission allPermission = new AllPermission(); - final Permissions permissions = new Permissions(); - permissions.add( allPermission ); - return permissions; - } - - public void refresh() - { - //To change body of implemented methods use File | Settings | File Templates. - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/dev-status.xml ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/dev-status.xml b/libraries/jini/javaspaces/dev-status.xml deleted file mode 100644 index dc92d29..0000000 --- a/libraries/jini/javaspaces/dev-status.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1"> - <status> - <codebase>early</codebase> - <!--none,early,beta,stable,mature--> - <documentation>brief</documentation> - <!-- none, brief, good, complete --> - <unittests>some</unittests> - <!-- none, some, good, complete --> - </status> - <licenses> - <license>ALv2</license> - </licenses> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/pom.xml b/libraries/jini/javaspaces/pom.xml deleted file mode 100644 index d84809c..0000000 --- a/libraries/jini/javaspaces/pom.xml +++ /dev/null @@ -1,83 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini-javaspaces</artifactId> - <name>Qi4j Library - Jini Javaspaces Services</name> - - <dependencies> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.api</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.testsupport</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.runtime</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.bootstrap</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.http</artifactId> - <version>${version.qi4j}</version> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.logging</artifactId> - <version>${version.qi4j}</version> - </dependency> - <dependency> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini-lookup</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini-transaction</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-core</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-ext</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>outrigger</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>start</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jsk-lib</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JavaSpacesService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JavaSpacesService.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JavaSpacesService.java deleted file mode 100644 index db70923..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JavaSpacesService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.Activatable; -import org.qi4j.api.service.ServiceComposite; - -@Mixins( OutriggerMixin.class ) -public interface JavaSpacesService extends Activatable, ServiceComposite -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JiniJavaSpacesServiceAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JiniJavaSpacesServiceAssembler.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JiniJavaSpacesServiceAssembler.java deleted file mode 100644 index b7be5a2..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/JiniJavaSpacesServiceAssembler.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import org.qi4j.bootstrap.Assembler; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.library.http.ServletInfo; - -public class JiniJavaSpacesServiceAssembler - implements Assembler -{ - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.addEntities( OutriggerConfiguration.class ); - ServletInfo servletInfo = new ServletInfo( "/jini/outrigger-dl.jar" ); - module.addServices( OutriggerDownloadServletService.class ).instantiateOnStartup().setMetaInfo( servletInfo ); - module.addServices( JavaSpacesService.class ).instantiateOnStartup(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerConfiguration.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerConfiguration.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerConfiguration.java deleted file mode 100644 index 8accf08..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import org.qi4j.api.common.Optional; -import org.qi4j.api.common.UseDefaults; -import org.qi4j.api.configuration.ConfigurationComposite; -import org.qi4j.api.property.Property; - -public interface OutriggerConfiguration extends ConfigurationComposite -{ - @Optional @UseDefaults Property<Boolean> useJrmp(); - - @Optional Property<String> hostInterface(); - - @Optional Property<String> securityPolicy(); - - @Optional Property<String> outriggerDlJarLocation(); - - /** - * The groups that this Reggie instance should be serving. - * This is a comma separated list of strings. - * - * @return the groups that Reggie is serving. - */ - @Optional Property<String> groups(); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerDownloadServletService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerDownloadServletService.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerDownloadServletService.java deleted file mode 100644 index b482e0a..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerDownloadServletService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceComposite; - -import javax.servlet.Servlet; - -@Mixins( ResourceServletMixin.class ) -public interface OutriggerDownloadServletService extends Servlet, ServiceComposite -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerMixin.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerMixin.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerMixin.java deleted file mode 100644 index eef45d0..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/OutriggerMixin.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import com.sun.jini.start.NonActivatableServiceDescriptor; -import net.jini.config.Configuration; -import net.jini.config.EmptyConfiguration; -import org.qi4j.api.common.Optional; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.service.Activatable; -import org.qi4j.library.http.HttpService; -import org.qi4j.library.http.Interface; -import org.qi4j.library.jini.lookup.Streams; - -import java.io.*; -import java.net.UnknownHostException; -import java.security.Policy; -import java.util.ArrayList; -import java.util.StringTokenizer; - -public class OutriggerMixin - implements Activatable -{ - @Optional @Service HttpService httpService; - @This org.qi4j.api.configuration.Configuration<OutriggerConfiguration> my; - - private NonActivatableServiceDescriptor.Created lookupCreated; - private File fileToCleanup; - - public void activate() - throws Exception - { - // Prepare a temporary directory. - File qi4j = new File( "qi4jtemp" ); - qi4j.mkdir(); - fileToCleanup = qi4j.getAbsoluteFile(); - File jini = new File( qi4j, "jini" ); - jini.mkdirs(); - File temp = File.createTempFile( "outrigger", "", jini ); - temp.delete(); - temp.mkdirs(); - // Start Outrigger - Configuration serviceDescConfig = EmptyConfiguration.INSTANCE; - String httpURLtext = my.configuration().outriggerDlJarLocation().get(); - if( httpURLtext == null ) - { - // If Http Service not running in this JVM, we need the Download URL from configuration. - if( httpService != null ) - { - httpURLtext = constructDownloadURL(); - } - } - String outriggerJarLocation = createOutriggerJars( temp ); - File outriggerJarFile = new File( outriggerJarLocation ); - String securityPolicyLocation = createSecurityPolicy( temp, outriggerJarFile ); - String outriggerConfig = createOutriggerConfig( temp ); - System.out.println( " Http: " + httpURLtext ); - System.out.println( " Security: " + Policy.getPolicy() ); - System.out.println( " Jar Location: " + outriggerJarLocation ); - System.out.println( "Configuration: " + outriggerConfig ); - NonActivatableServiceDescriptor serviceDescriptor = new NonActivatableServiceDescriptor( - httpURLtext, - securityPolicyLocation, - outriggerJarLocation, - "com.sun.jini.outrigger.TransientOutriggerImpl", - new String[]{ outriggerConfig } ); - lookupCreated = (NonActivatableServiceDescriptor.Created) serviceDescriptor.create( serviceDescConfig ); - - } - - public void passivate() throws Exception - { - // How to shutdown properly??? - removeFile( fileToCleanup ); - } - - private String createOutriggerConfig( File dir ) - throws IOException - { - StringBuffer configuration = new StringBuffer(); - if( my.configuration().useJrmp().get() ) - { - System.out.println( "Using JRMP..." ); - configuration.append( "import net.jini.jrmp.JrmpExporter;\n" + - "import net.jini.core.discovery.LookupLocator;\n" + - "\n" + - "com.sun.jini.outrigger\n" + - "{\n" + - " serverExporter = new JrmpExporter();\n" ); - } - else - { - System.out.println( "Using JERI..." ); - configuration.append( "import net.jini.jeri.BasicILFactory;\n" + - "import net.jini.jeri.BasicJeriExporter;\n" + - "import net.jini.jeri.tcp.TcpServerEndpoint;\n" + - "import net.jini.core.discovery.LookupLocator;\n" + - "com.sun.jini.outrigger\n" + - "{" + - " private invocationLayerFactory = new BasicILFactory();\n" + - " serverExporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0),\n" + - " invocationLayerFactory,\n" + - " false,\n" + - " true);\n" ); - } - configuration.append( " initialLookupGroups = new String[] {" ); - String groupData = my.configuration().groups().get(); - String[] groups; - if( groupData != null ) - { - groups = convert( groupData ); - } - else - { - groups = new String[]{ "qi4j" }; - } - boolean first = true; - for( String group : groups ) - { - if( !first ) - { - configuration.append( ", " ); - } - first = false; - configuration.append( "\"" ); - configuration.append( group ); - configuration.append( "\"" ); - } - - configuration.append( "};\n}" ); - - File outriggerConfigFile = new File( dir, "outrigger.conf" ); - if( !outriggerConfigFile.exists() ) - { - InputStream outriggerConfig = new ByteArrayInputStream( configuration.toString().getBytes() ); - copyStreamToFile( outriggerConfig, outriggerConfigFile ); - } - return outriggerConfigFile.getAbsolutePath(); - } - - private String[] convert( String data ) - { - if( data == null ) - { - return new String[0]; - } - ArrayList<String> result = new ArrayList<String>(); - StringTokenizer st = new StringTokenizer( data, ",", false ); - while( st.hasMoreTokens() ) - { - String token = st.nextToken(); - result.add( token ); - } - String[] retVal = new String[result.size()]; - return result.toArray( retVal ); - } - - private String createOutriggerJars( File temp ) - throws IOException - { - File outriggerJar = new File( temp, "outrigger-2.1.1.jar" ); - if( !outriggerJar.exists() ) - { - InputStream outrigger = getClass().getResourceAsStream( "outrigger-2.1.1.jar" ); - copyStreamToFile( outrigger, outriggerJar ); - } - return outriggerJar.getAbsolutePath(); - } - - private void removeFile( File fileToCleanup ) - { - if( fileToCleanup == null ) - { - return; - } - - File[] files = fileToCleanup.listFiles(); - if( files == null ) - { - return; - } - for( File file : files ) - { - removeFile( file ); - } - fileToCleanup.delete(); - } - - private String constructDownloadURL() - throws UnknownHostException - { - Interface[] interfaces = httpService.interfacesServed(); - String host = interfaces[ 0 ].hostName(); - int port = interfaces[ 0 ].port(); - String protocol = interfaces[ 0 ].protocol().toString(); - return protocol + "://" + host + ":" + port + "/jini/outrigger-dl.jar"; - } - - private String createSecurityPolicy( File tempDir, File outriggerJarFile ) - throws IOException - { - String securityPolicy = my.configuration().securityPolicy().get(); - if( securityPolicy == null || "".equals( securityPolicy ) ) - { - securityPolicy = "grant { permission java.security.AllPermission; };"; - } - File securityPolicyFile = new File( tempDir, "outrigger-security.policy" ); - copyStringToFile( securityPolicy, securityPolicyFile ); - return securityPolicyFile.getAbsolutePath(); - } - - private void copyStringToFile( String securityPolicy, File securityPolicyFile ) - throws IOException - { - ByteArrayInputStream bais = new ByteArrayInputStream( securityPolicy.getBytes() ); - copyStreamToFile( bais, securityPolicyFile ); - } - - private void copyStreamToFile( InputStream inputStream, File destinationFile ) - throws IOException - { - destinationFile = destinationFile.getAbsoluteFile(); - File parentFile = destinationFile.getParentFile(); - if( !parentFile.exists() ) - { - parentFile.mkdirs(); - } - FileOutputStream fos = new FileOutputStream( destinationFile ); - Streams.copyStream( inputStream, fos, true ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/ResourceServletMixin.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/ResourceServletMixin.java b/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/ResourceServletMixin.java deleted file mode 100644 index 07a2e14..0000000 --- a/libraries/jini/javaspaces/src/main/java/org/qi4j/library/jini/javaspaces/ResourceServletMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import org.qi4j.library.jini.lookup.Streams; - -public class ResourceServletMixin extends HttpServlet -{ - protected void doGet( HttpServletRequest request, HttpServletResponse response ) - throws ServletException, IOException - { - InputStream in = getClass().getResourceAsStream( "outrigger-dl-2.1.1.jar" ); - response.setContentType( "application/java" ); - OutputStream out = response.getOutputStream(); - Streams.copyStream( in, out, true ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-2.1.1.jar ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-2.1.1.jar b/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-2.1.1.jar deleted file mode 100644 index e5319ef..0000000 Binary files a/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-2.1.1.jar and /dev/null differ http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-dl-2.1.1.jar ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-dl-2.1.1.jar b/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-dl-2.1.1.jar deleted file mode 100644 index e5319ef..0000000 Binary files a/libraries/jini/javaspaces/src/main/resources/org/qi4j/library/jini/javaspaces/outrigger-dl-2.1.1.jar and /dev/null differ http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/test/java/org/qi4j/library/jini/javaspaces/OutriggerStartTest.java ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/test/java/org/qi4j/library/jini/javaspaces/OutriggerStartTest.java b/libraries/jini/javaspaces/src/test/java/org/qi4j/library/jini/javaspaces/OutriggerStartTest.java deleted file mode 100644 index 05d3c32..0000000 --- a/libraries/jini/javaspaces/src/test/java/org/qi4j/library/jini/javaspaces/OutriggerStartTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.javaspaces; - -import java.io.IOException; -import java.security.AllPermission; -import java.security.CodeSource; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.Policy; -import java.util.Collection; -import java.util.logging.Formatter; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; -import net.jini.core.lookup.ServiceTemplate; -import net.jini.discovery.DiscoveryEvent; -import net.jini.discovery.DiscoveryListener; -import net.jini.discovery.DiscoveryManagement; -import net.jini.discovery.LookupDiscoveryManager; -import net.jini.lookup.LookupCache; -import net.jini.lookup.ServiceDiscoveryEvent; -import net.jini.lookup.ServiceDiscoveryListener; -import net.jini.lookup.ServiceDiscoveryManager; -import net.jini.security.policy.DynamicPolicyProvider; -import net.jini.space.JavaSpace05; -import org.junit.Test; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.entitystore.memory.MemoryEntityStoreService; -import org.qi4j.library.http.JettyServiceAssembler; -import org.qi4j.library.jini.lookup.JiniLookupServiceAssembler; -import org.qi4j.library.jini.transaction.JiniTransactionServiceAssembler; -import org.qi4j.test.AbstractQi4jTest; - -public class OutriggerStartTest extends AbstractQi4jTest -{ - private static Logger logger = Logger.getLogger( "" ); - - static - { - Handler[] handlers = logger.getHandlers(); - for( Handler handler : handlers ) - { - Formatter formatter = new SimpleFormatter(); - handler.setFormatter( formatter ); - } - logger.setLevel( Level.FINEST ); - - Policy basePolicy = new AllPolicy(); - DynamicPolicyProvider policyProvider = new DynamicPolicyProvider( basePolicy ); - Policy.setPolicy( policyProvider ); - } - - - public void assemble( ModuleAssembly module ) throws AssemblyException - { - new JiniTransactionServiceAssembler().assemble( module ); - new JiniLookupServiceAssembler().assemble( module ); - new JiniJavaSpacesServiceAssembler().assemble( module ); - new JettyServiceAssembler().assemble( module ); - module.addObjects( Holder.class ); - module.addServices( MemoryEntityStoreService.class ); - } - - @Test - public void whenStartingOutriggerExpectFoundJavaSpace05() - throws Exception - { - LookupCache cache = initialize(); - MyServiceDiscoveryListener listener = new MyServiceDiscoveryListener(); - cache.addListener( listener ); - Holder object = objectBuilderFactory.newObject( Holder.class ); - synchronized( this ) - { - if( !listener.added ) - { - wait( 5000 ); - } - } - org.junit.Assert.assertTrue( listener.added ); - } - - - private LookupCache initialize() - throws IOException - { - DiscoveryManagement discoveryManager = new LookupDiscoveryManager( null, null, new MyDiscoveryListener() ); - ServiceDiscoveryManager sdm = new ServiceDiscoveryManager( discoveryManager, null ); - Class[] types = new Class[]{ JavaSpace05.class }; - ServiceTemplate template = new ServiceTemplate( null, types, null ); - LookupCache lookupCache = sdm.createLookupCache( template, null, null ); - return lookupCache; - - } - - public static class Holder - { - @Service JavaSpacesService service; - } - - private static class MyDiscoveryListener - implements DiscoveryListener - { - - public void discovered( DiscoveryEvent e ) - { - printEvent( e, "Discovered: " ); - } - - public void discarded( DiscoveryEvent e ) - { - printEvent( e, "Discarded: " ); - } - - private void printEvent( DiscoveryEvent e, String message ) - { - Collection<String[]> collection = e.getGroups().values(); - for( String[] array : collection ) - { - StringBuffer groups = new StringBuffer(); - boolean first = true; - for( String group : array ) - { - if( !first ) - { - groups.append( "," ); - } - first = false; - groups.append( group ); - System.out.println( message + groups ); - } - } - } - } - - private class MyServiceDiscoveryListener - implements ServiceDiscoveryListener - { - boolean added = false; - boolean removed = false; - - public MyServiceDiscoveryListener() - { - } - - public void serviceAdded( ServiceDiscoveryEvent event ) - { - synchronized( OutriggerStartTest.this ) - { - logger.info( "Added: " + event.getPostEventServiceItem() ); - added = true; - OutriggerStartTest.this.notifyAll(); - } - } - - public void serviceRemoved( ServiceDiscoveryEvent event ) - { - synchronized( OutriggerStartTest.this ) - { - logger.info( "Removed: " + event.getPostEventServiceItem() ); - removed = true; - OutriggerStartTest.this.notifyAll(); - } - } - - public void serviceChanged( ServiceDiscoveryEvent event ) - { - } - } - - public static class AllPolicy extends Policy - { - - public AllPolicy() - { - } - - public PermissionCollection getPermissions( CodeSource codeSource ) - { - Permissions allPermission; - allPermission = new Permissions(); - allPermission.add( new AllPermission() ); - return allPermission; - } - - public void refresh() - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/javaspaces/src/test/resources/org/qi4j/library/http/JettyService.properties ---------------------------------------------------------------------- diff --git a/libraries/jini/javaspaces/src/test/resources/org/qi4j/library/http/JettyService.properties b/libraries/jini/javaspaces/src/test/resources/org/qi4j/library/http/JettyService.properties deleted file mode 100644 index 7a1adb8..0000000 --- a/libraries/jini/javaspaces/src/test/resources/org/qi4j/library/http/JettyService.properties +++ /dev/null @@ -1,3 +0,0 @@ -port=8040 -hostName=127.0.0.1 -resourcePath=/ http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/dev-status.xml ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/dev-status.xml b/libraries/jini/lookup/dev-status.xml deleted file mode 100644 index dc92d29..0000000 --- a/libraries/jini/lookup/dev-status.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1"> - <status> - <codebase>early</codebase> - <!--none,early,beta,stable,mature--> - <documentation>brief</documentation> - <!-- none, brief, good, complete --> - <unittests>some</unittests> - <!-- none, some, good, complete --> - </status> - <licenses> - <license>ALv2</license> - </licenses> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/pom.xml b/libraries/jini/lookup/pom.xml deleted file mode 100644 index 86a6b70..0000000 --- a/libraries/jini/lookup/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <groupId>org.qi4j.library.jini</groupId> - <artifactId>org.qi4j.library.jini-lookup</artifactId> - <name>Qi4j Library - Jini Lookup Service</name> - - <dependencies> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.api</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.testsupport</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.runtime</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.bootstrap</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.http</artifactId> - <version>${version.qi4j}</version> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.logging</artifactId> - <version>${version.qi4j}</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-core</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jini-ext</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>reggie</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>start</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.river</groupId> - <artifactId>jsk-lib</artifactId> - <version>2.1.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/JiniLookupServiceAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/JiniLookupServiceAssembler.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/JiniLookupServiceAssembler.java deleted file mode 100644 index 12a025f..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/JiniLookupServiceAssembler.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import org.qi4j.bootstrap.Assembler; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.library.http.ServletInfo; - -public class JiniLookupServiceAssembler - implements Assembler -{ - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.addEntities( ReggieConfiguration.class ); - ServletInfo servletInfo = new ServletInfo( "/jini/reggie-dl.jar" ); - module.addServices( ReggieDownloadServletService.class ).instantiateOnStartup().setMetaInfo( servletInfo ); - module.addServices( ServiceRegistryService.class ).instantiateOnStartup(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieConfiguration.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieConfiguration.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieConfiguration.java deleted file mode 100644 index 6eb357b..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import org.qi4j.api.common.Optional; -import org.qi4j.api.common.UseDefaults; -import org.qi4j.api.configuration.ConfigurationComposite; -import org.qi4j.api.property.Property; - -public interface ReggieConfiguration extends ConfigurationComposite -{ - @Optional @UseDefaults Property<Boolean> useJrmp(); - - @Optional Property<String> hostInterface(); - - @Optional Property<String> securityPolicy(); - - @Optional Property<String> reggieDlJarLocation(); - - /** - * The groups that this Reggie instance should be serving. - * This is a comma separated list of strings. - * - * @return the groups that Reggie is serving. - */ - @Optional Property<String> groups(); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieDownloadServletService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieDownloadServletService.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieDownloadServletService.java deleted file mode 100644 index ab31569..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieDownloadServletService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceComposite; - -import javax.servlet.Servlet; - -@Mixins( ResourceServletMixin.class ) -public interface ReggieDownloadServletService extends Servlet, ServiceComposite -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieMixin.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieMixin.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieMixin.java deleted file mode 100644 index ddfeaad..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ReggieMixin.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import com.sun.jini.admin.DestroyAdmin; -import com.sun.jini.start.NonActivatableServiceDescriptor; -import net.jini.admin.Administrable; -import net.jini.config.Configuration; -import net.jini.config.EmptyConfiguration; -import org.qi4j.api.common.Optional; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.service.Activatable; -import org.qi4j.library.http.HttpService; -import org.qi4j.library.http.Interface; - -import java.io.*; -import java.net.UnknownHostException; -import java.security.Policy; -import java.util.ArrayList; -import java.util.StringTokenizer; - -public class ReggieMixin - implements Activatable -{ - @Optional @Service HttpService httpService; - @This org.qi4j.api.configuration.Configuration<ReggieConfiguration> my; - - private NonActivatableServiceDescriptor.Created lookupCreated; - private File fileToCleanup; - - public void activate() - throws Exception - { - // Prepare a temporary directory. - File qi4j = new File( "qi4jtemp" ); - qi4j.mkdir(); - fileToCleanup = qi4j.getAbsoluteFile(); - File jini = new File( qi4j, "jini" ); - jini.mkdirs(); - File temp = File.createTempFile( "reggie", "", jini ); - temp.delete(); - boolean success = temp.mkdirs(); - // Start Reggie - Configuration serviceDescConfig = EmptyConfiguration.INSTANCE; - String httpURL = my.configuration().reggieDlJarLocation().get(); - if( httpURL == null ) - { - // If Http Service not running in this JVM, we need the Download URL from configuration. - if( httpService != null ) - { - httpURL = constructDownloadURL(); - } - } - String reggieJarLocation = createReggieJars( temp ); - File reggieJarFile = new File( reggieJarLocation ); - String securityPolicyLocation = createSecurityPolicy( temp, reggieJarFile ); - String reggieConfig = createReggieConfig( temp ); - System.out.println( "Policy: " + Policy.getPolicy() ); - NonActivatableServiceDescriptor serviceDescriptor = new NonActivatableServiceDescriptor( - httpURL, - securityPolicyLocation, - reggieJarLocation, - "com.sun.jini.reggie.TransientRegistrarImpl", - new String[]{ reggieConfig } ); - lookupCreated = (NonActivatableServiceDescriptor.Created) serviceDescriptor.create( serviceDescConfig ); - } - - public void passivate() throws Exception - { - System.out.println( "Destroying Reggie." ); - Object admin = ( (Administrable) lookupCreated.proxy ).getAdmin(); - ( (DestroyAdmin) admin ).destroy(); - removeFile( fileToCleanup ); - } - - private String createReggieConfig( File dir ) - throws IOException - { - StringBuffer configuration = new StringBuffer(); - if( my.configuration().useJrmp().get() ) - { - System.out.println( "Using JRMP..." ); - configuration.append( "import net.jini.jrmp.JrmpExporter;\n" + - "\n" + - "com.sun.jini.reggie {\n" + - "\n" + - " serverExporter = new JrmpExporter();\n" ); - } - else - { - System.out.println( "Using JERI..." ); - configuration.append( "import net.jini.jeri.BasicILFactory;\n" + - "import net.jini.jeri.BasicJeriExporter;\n" + - "import net.jini.jeri.tcp.TcpServerEndpoint;\n" + - "\n" + - "com.sun.jini.reggie\n" + - "{\n" + - " private invocationLayerFactory = new BasicILFactory();\n" + - " serverExporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0),\n" + - " invocationLayerFactory,\n" + - " false,\n" + - " true);\n" ); - } - configuration.append( " initialMemberGroups = new String[] {" ); - String groupData = my.configuration().groups().get(); - String[] groups; - if( groupData != null ) - { - groups = convert( groupData ); - } - else - { - groups = new String[]{ "qi4j" }; - } - boolean first = true; - for( String group : groups ) - { - if( !first ) - { - configuration.append( ", " ); - } - first = false; - configuration.append( " \"" ); - configuration.append( group ); - configuration.append( "\" " ); - } - - configuration.append( "};\n}" ); - File reggieConfigFile = new File( dir, "reggie.conf" ); - if( !reggieConfigFile.exists() ) - { - InputStream reggieConfig = new ByteArrayInputStream( configuration.toString().getBytes() ); - copyStreamToFile( reggieConfig, reggieConfigFile ); - } - return reggieConfigFile.getAbsolutePath(); - } - - private String[] convert( String data ) - { - if( data == null ) - { - return new String[0]; - } - ArrayList<String> result = new ArrayList<String>(); - StringTokenizer st = new StringTokenizer( data, ",", false ); - while( st.hasMoreTokens() ) - { - String token = st.nextToken(); - result.add( token ); - } - String[] retVal = new String[result.size()]; - return result.toArray( retVal ); - } - - - private String createReggieJars( File temp ) - throws IOException - { - File reggieJar = new File( temp, "reggie-2.1.1.jar" ); - if( !reggieJar.exists() ) - { - InputStream reggie = getClass().getResourceAsStream( "reggie-2.1.1.jar" ); - copyStreamToFile( reggie, reggieJar ); - } - return reggieJar.getAbsolutePath(); - } - - private void removeFile( File fileToCleanup ) - { - if( fileToCleanup == null ) - { - return; - } - - File[] files = fileToCleanup.listFiles(); - if( files == null ) - { - return; - } - for( File file : files ) - { - removeFile( file ); - } - fileToCleanup.delete(); - } - - private String constructDownloadURL() - throws UnknownHostException - { - Interface[] interfaces = httpService.interfacesServed(); - String host = interfaces[ 0 ].hostName(); - int port = interfaces[ 0 ].port(); - String protocol = interfaces[ 0 ].protocol().toString(); - return protocol + "://" + host + ":" + port + "/jini/reggie-dl.jar"; - } - - private String createSecurityPolicy( File tempDir, File reggieJarFile ) - throws IOException - { - String securityPolicy = my.configuration().securityPolicy().get(); - if( securityPolicy == null || "".equals( securityPolicy ) ) - { - securityPolicy = "grant { permission java.security.AllPermission; };"; - } - File securityPolicyFile = new File( tempDir, "reggie-security.policy" ); - copyStringToFile( securityPolicy, securityPolicyFile ); - return securityPolicyFile.getAbsolutePath(); - } - - private void copyStringToFile( String securityPolicy, File securityPolicyFile ) - throws IOException - { - ByteArrayInputStream bais = new ByteArrayInputStream( securityPolicy.getBytes() ); - copyStreamToFile( bais, securityPolicyFile ); - } - - private void copyStreamToFile( InputStream inputStream, File destinationFile ) - throws IOException - { - destinationFile = destinationFile.getAbsoluteFile(); - File parentFile = destinationFile.getParentFile(); - if( !parentFile.exists() ) - { - parentFile.mkdirs(); - } - FileOutputStream fos = new FileOutputStream( destinationFile ); - Streams.copyStream( inputStream, fos, true ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ResourceServletMixin.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ResourceServletMixin.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ResourceServletMixin.java deleted file mode 100644 index de9e6d5..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ResourceServletMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -public class ResourceServletMixin extends HttpServlet -{ - protected void doGet( HttpServletRequest request, HttpServletResponse response ) - throws ServletException, IOException - { - InputStream in = getClass().getResourceAsStream( "reggie-dl-2.1.1.jar" ); - response.setContentType( "application/java" ); - OutputStream out = response.getOutputStream(); - Streams.copyStream( in, out, true ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/25dbfc23/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ServiceRegistryService.java ---------------------------------------------------------------------- diff --git a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ServiceRegistryService.java b/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ServiceRegistryService.java deleted file mode 100644 index 9050a66..0000000 --- a/libraries/jini/lookup/src/main/java/org/qi4j/library/jini/lookup/ServiceRegistryService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.library.jini.lookup; - -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.Activatable; -import org.qi4j.api.service.ServiceComposite; - -@Mixins( { ReggieMixin.class } ) -public interface ServiceRegistryService extends Activatable, ServiceComposite -{ -}
