Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codebase/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
build.longname = Open LVC Disco
build.shortname = disco
build.version = 1.2.0
build.number = 7
build.number = 8

#################################
# Java Development Kit Settings #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public void setRtiProvider( RtiProvider provider )
loadDefaultModules();

// re-add extension modules
// Doing this last means that extension modules don't
// respect overrides, which is intentional.
registerExtensionModules( this.extensionModules.toArray(new String[0]) );
}
}
Expand Down Expand Up @@ -455,7 +457,7 @@ public File getFomOverridePath()
/////////////////////////////////////////////////////////////////////////////////////////
/**
* Get the list of all registered FOM modules. This is the union of the set of default
* modules plus any added through {@link #registerExtensionModules(File...)}.
* modules plus any added through {@link #registerExtensionModules}.
* <p/>
* If you have a custom FOM Mapper, remember to make sure any required FOM Module is also
* getting loaded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Random;
import java.util.stream.Stream;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.openlvc.disco.DiscoException;
import org.openlvc.disco.OpsCenter;
Expand Down Expand Up @@ -60,7 +61,6 @@
import hla.rti1516e.ParameterHandleValueMap;
import hla.rti1516e.RTIambassador;
import hla.rti1516e.ResignAction;
import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.exceptions.FederateAlreadyExecutionMember;
import hla.rti1516e.exceptions.FederateNameAlreadyInUse;
import hla.rti1516e.exceptions.FederationExecutionAlreadyExists;
Expand Down Expand Up @@ -355,7 +355,7 @@ private void initializeFederation()
try
{
logger.debug( "Connecting to RTI" );
this.rtiamb = RtiFactoryFactory.getRtiFactory().getRtiAmbassador();
this.rtiamb = RprRtiFactoryFactory.getRtiFactory().getRtiAmbassador();
this.fedamb = new FederateAmbassador( this );
this.rtiamb.connect( this.fedamb,
CallbackModel.HLA_IMMEDIATE,
Expand Down Expand Up @@ -475,38 +475,48 @@ private void cleanupFederation()
try
{
// Resign from the federation
logger.info( "Resigning from HLA federation" );
this.rtiamb.resignFederationExecution( ResignAction.DELETE_OBJECTS_THEN_DIVEST );
}
catch( RTIexception rtie )
{
logger.warn( "Error while resigning from HLA federation: "+rtie.getMessage() );
}

// Delete the federation, to be a good citizen. Will get told off if people are
// still using it, so expect that.
try
{
this.rtiamb.destroyFederationExecution( rprConfiguration.getFederationName() );
}
catch( RTIexception rtie )
// Delete the federation, to be a good citizen (unless we're
// using the MAK RTI, which prefers to clean it up automatically
// after we disconnect).
// Will get told off if people are still using it, so expect that.
if( rprConfiguration.getRtiProvider() != RtiProvider.Mak )
{
// no-op
}
catch( Exception e )
{
e.printStackTrace();
try
{
logger.info( "Destroying federation execution" );
this.rtiamb.destroyFederationExecution( rprConfiguration.getFederationName() );
}
catch( RTIexception rtie )
{
logger.catching( Level.WARN, rtie );
}
catch( Exception e )
{
logger.catching( e );
}
}

// Disconnect from the RTI and then we are allll cleaned up
try
{
logger.info( "Disconnecting from RTI" );
this.rtiamb.disconnect();
this.rtiambConnected = false;
}
catch( RTIexception rtie )
{
throw new DiscoException( "Error disconnecting from RTI: "+rtie.getMessage(), rtie );
}

logger.info( "Successfully disconnected from RTI" );
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2015 Open LVC Project.
*
* This file is part of Open LVC Disco.
*
* 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.openlvc.disco.connection.rpr;

import java.util.HashSet;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.Set;

import hla.rti1516e.RtiFactory;
import hla.rti1516e.exceptions.RTIinternalError;

/**
* A custom implementation of {@link hla.rti1516e.RtiFactoryFactory} that ensures that the same
* classloader is used for all attempts to {@link hla.rti1516e.RtiFactory}.
* <p>
* <b>Note:</b> the first invocation of a method from this class MUST occur on the same thread
* as the prior invocation of {@link org.openlvc.disco.utils.ClassLoaderUtils#extendClasspath}.
*/
public class RprRtiFactoryFactory
{
//----------------------------------------------------------
// STATIC VARIABLES
//----------------------------------------------------------
private static ClassLoader classLoader;

//----------------------------------------------------------
// INSTANCE VARIABLES
//----------------------------------------------------------

//----------------------------------------------------------
// CONSTRUCTORS
//----------------------------------------------------------
public RprRtiFactoryFactory() {}

//----------------------------------------------------------
// INSTANCE METHODS
//----------------------------------------------------------

//==========================================================================================
//----------------------------- Accessor and Mutator Methods -------------------------------
//==========================================================================================

//----------------------------------------------------------
// STATIC METHODS
//----------------------------------------------------------

public static RtiFactory getRtiFactory( String name ) throws RTIinternalError
{
for( RtiFactory rtiFactory : ServiceLoader.load(RtiFactory.class, getClassLoader()) )
{
if( rtiFactory.rtiName().equals(name) )
{
return rtiFactory;
}
}

throw new RTIinternalError( "Cannot find factory matching "+name );
}

public static RtiFactory getRtiFactory() throws RTIinternalError
{
ServiceLoader<RtiFactory> loader = ServiceLoader.load( RtiFactory.class, getClassLoader() );
Iterator<RtiFactory> iterator = loader.iterator();
if( iterator.hasNext() )
{
return iterator.next();
}
else
{
throw new RTIinternalError( "Cannot find factory" );
}
}

public static Set<RtiFactory> getAvailableRtiFactories()
{
Set<RtiFactory> factories = new HashSet<>();

for( RtiFactory rtiFactory : ServiceLoader.load(RtiFactory.class, getClassLoader()) )
{
factories.add( rtiFactory );
}

return factories;
}

/**
* @return the current thread's classloader if possible, or {@code null} if the system
* classloader is to be used.
*/
private static ClassLoader getClassLoader()
{
if( classLoader == null )
{
// prefer thread context classloader, since that'll usually
// be the one with the extended classpath
classLoader = Thread.currentThread().getContextClassLoader();
}

return classLoader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.openlvc.disco.connection.rpr.types;

import org.openlvc.disco.DiscoException;
import org.openlvc.disco.connection.rpr.RprRtiFactoryFactory;

import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.encoding.DataElement;
import hla.rti1516e.encoding.DataElementFactory;
import hla.rti1516e.encoding.HLAASCIIchar;
Expand Down Expand Up @@ -305,7 +305,7 @@ private static final hla.rti1516e.encoding.EncoderFactory factory()
{
try
{
RTI_FACTORY = RtiFactoryFactory.getRtiFactory().getEncoderFactory();
RTI_FACTORY = RprRtiFactoryFactory.getRtiFactory().getEncoderFactory();
}
catch( RTIinternalError e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Iterator;

import org.openlvc.disco.DiscoException;
import org.openlvc.disco.connection.rpr.RprRtiFactoryFactory;

import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.encoding.ByteWrapper;
import hla.rti1516e.encoding.DataElement;
import hla.rti1516e.encoding.DataElementFactory;
Expand Down Expand Up @@ -52,9 +52,9 @@ public WrappedHlaFixedArray( T... values )

try
{
this.internal = RtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedArray( values );
this.internal = RprRtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedArray( values );
}
catch( RTIinternalError e )
{
Expand All @@ -68,9 +68,9 @@ public WrappedHlaFixedArray( DataElementFactory<T> factory, int size )

try
{
this.internal = RtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedArray( factory, size );
this.internal = RprRtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedArray( factory, size );
}
catch( RTIinternalError e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Iterator;

import org.openlvc.disco.DiscoException;
import org.openlvc.disco.connection.rpr.RprRtiFactoryFactory;

import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.encoding.ByteWrapper;
import hla.rti1516e.encoding.DataElement;
import hla.rti1516e.encoding.DataElementFactory;
Expand Down Expand Up @@ -52,9 +52,9 @@ public WrappedHlaVariableArray( DataElementFactory<T> factory, T... values )

try
{
this.internal = RtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAvariableArray( factory, values );
this.internal = RprRtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAvariableArray( factory, values );
}
catch( RTIinternalError e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Iterator;

import org.openlvc.disco.DiscoException;
import org.openlvc.disco.connection.rpr.RprRtiFactoryFactory;

import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.encoding.ByteWrapper;
import hla.rti1516e.encoding.DataElement;
import hla.rti1516e.encoding.DecoderException;
Expand Down Expand Up @@ -50,9 +50,9 @@ public WrappedHlaFixedRecord()

try
{
this.internal = RtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedRecord();
this.internal = RprRtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAfixedRecord();
}
catch( RTIinternalError e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.openlvc.disco.connection.rpr.types.variant;

import org.openlvc.disco.DiscoException;
import org.openlvc.disco.connection.rpr.RprRtiFactoryFactory;
import org.openlvc.disco.connection.rpr.types.enumerated.EnumHolder;
import org.openlvc.disco.connection.rpr.types.enumerated.ExtendedDataElement;

import hla.rti1516e.RtiFactoryFactory;
import hla.rti1516e.encoding.ByteWrapper;
import hla.rti1516e.encoding.DataElement;
import hla.rti1516e.encoding.DecoderException;
Expand Down Expand Up @@ -50,9 +50,9 @@ public WrappedHlaVariantRecord( T discriminant )

try
{
this.internal = RtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAvariantRecord( new EnumHolder<>(discriminant) );
this.internal = RprRtiFactoryFactory.getRtiFactory()
.getEncoderFactory()
.createHLAvariantRecord( new EnumHolder<>(discriminant) );
}
catch( RTIinternalError e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public class ClassLoaderUtils
/**
* Add a given path or set of paths to a custom classloader, and sets that as the ClassLoader
* for the current Thread
* <p>
* <b>Note:</b> because we're altering the current thread's classloader, this is only useful
* if performed on the same thread as the first call to a method of
* {@link org.openlvc.disco.connection.rpr.RprRtiFactoryFactory}.
*
* @param paths The paths to add to the lookup set
* @throws DiscoException If there any invalid files are provided
Expand Down