📄 wrappermanager.java
字号:
String error = e.getMessage();
if ( error == null )
{
error = e.toString();
}
return error;
}
catch ( Throwable e )
{
if ( m_debug )
{
m_out.println( "Loading native library failed: " + file + " Cause: " + e );
}
String error = e.toString();
return error;
}
}
/**
* Java 1.5 and above supports the ability to register the WrapperManager
* MBean internally.
*/
private static void registerMBean( Object mbean, String name )
{
Class classManagementFactory;
try
{
classManagementFactory = Class.forName( "java.lang.management.ManagementFactory" );
}
catch ( ClassNotFoundException e )
{
if ( m_debug )
{
m_out.println( "Registering MBeans not supported by current JVM: " + name );
}
return;
}
try
{
// This code uses reflection so it combiles on older JVMs.
// The original code is as follows:
// javax.management.MBeanServer mbs =
// java.lang.management.ManagementFactory.getPlatformMBeanServer();
// javax.management.ObjectName oName = new javax.management.ObjectName( name );
// mbs.registerMBean( mbean, oName );
// The version of the above code using reflection follows.
Class classMBeanServer = Class.forName( "javax.management.MBeanServer" );
Class classObjectName = Class.forName( "javax.management.ObjectName" );
Method methodGetPlatformMBeanServer =
classManagementFactory.getMethod( "getPlatformMBeanServer", null );
Constructor constructorObjectName =
classObjectName.getConstructor( new Class[] {String.class} );
Method methodRegisterMBean = classMBeanServer.getMethod(
"registerMBean", new Class[] {Object.class, classObjectName} );
Object mbs = methodGetPlatformMBeanServer.invoke( null, null );
Object oName = constructorObjectName.newInstance( new Object[] {name} );
methodRegisterMBean.invoke( mbs, new Object[] {mbean, oName} );
if ( m_debug )
{
m_out.println( "Registered MBean with Platform MBean Server: " + name );
}
}
catch ( Throwable t )
{
m_err.println( "Unable to register the " + name + " MBean." );
t.printStackTrace();
}
}
/**
* Searches for a file on a path.
*
* @param file File to look for.
* @param path Path to be searched.
*
* @return Reference to thr file object if found, otherwise null.
*/
private static File locateFileOnPath( String file, String path )
{
// A library path exists but the library was not found on it.
String pathSep = System.getProperty( "path.separator" );
// Search for the file on the library path to verify that it does not
// exist, it could be some other problem
StringTokenizer st = new StringTokenizer( path, pathSep );
while( st.hasMoreTokens() )
{
File libFile = new File( new File( st.nextToken() ), file );
if ( libFile.exists() )
{
return libFile;
}
}
return null;
}
/**
* Generates a detailed native library base name which is made up of the
* base name, the os name, architecture, and the bits of the current JVM,
* not the platform.
*
* @return A detailed native library base name.
*/
private static String generateDetailedNativeLibraryBaseName( String baseName,
int jvmBits,
boolean universal )
{
// Generate an os name. Most names are used as is, but some are modified.
String os = System.getProperty( "os.name", "" ).toLowerCase();
if ( os.startsWith( "windows" ) )
{
os = "windows";
}
else if ( os.equals( "sunos" ) )
{
os = "solaris";
}
else if ( os.equals( "hp-ux" ) || os.equals( "hp-ux64" ) )
{
os = "hpux";
}
else if ( os.equals( "mac os x" ) )
{
os = "macosx";
}
else if ( os.equals( "unix_sv" ) )
{
os = "unixware";
}
// Generate an architecture name.
String arch = System.getProperty( "os.arch", "" ).toLowerCase();
if ( universal )
{
arch = "universal";
}
else
{
if ( arch.equals( "amd64" ) || arch.equals( "athlon" ) || arch.equals( "ia32" ) ||
arch.equals( "ia64" ) || arch.equals( "x86_64" ) || arch.equals( "i686" ) ||
arch.equals( "i586" ) || arch.equals( "i486" ) || arch.equals( "i386" ) )
{
arch = "x86";
}
else if ( arch.startsWith( "sparc" ) )
{
arch = "sparc";
}
else if ( arch.equals( "power" ) || arch.equals( "powerpc" ) || arch.equals( "ppc64" ) )
{
arch = "ppc";
}
else if ( arch.equals( "pa_risc" ) || arch.equals( "pa-risc" ) )
{
arch = "parisc";
}
}
return baseName + "-" + os + "-" + arch + "-" + jvmBits;
}
/**
* Searches for and then loads the native library. This method will attempt
* locate the wrapper library using one of the following 3 naming
*/
private static void initializeNativeLibrary()
{
// Resolve the osname and osarch for the currect system.
String osName = System.getProperty( "os.name" ).toLowerCase();
// Look for the base name of the library.
String baseName = System.getProperty( "wrapper.native_library" );
if ( baseName == null )
{
// This should only happen if an old version of the Wrapper binary is being used.
m_out.println( "WARNING - The wrapper.native_library system property was not" );
m_out.println( " set. Using the default value, 'wrapper'." );
baseName = "wrapper";
}
String[] detailedNames = new String[4];
if ( m_jvmBits > 0 )
{
detailedNames[0] = generateDetailedNativeLibraryBaseName( baseName, m_jvmBits, false );
if ( osName.startsWith( "mac" ) )
{
detailedNames[1] = generateDetailedNativeLibraryBaseName( baseName, m_jvmBits, true );
}
}
else
{
detailedNames[0] = generateDetailedNativeLibraryBaseName( baseName, 32, false );
detailedNames[1] = generateDetailedNativeLibraryBaseName( baseName, 64, false );
if ( osName.startsWith( "mac" ) )
{
detailedNames[2] = generateDetailedNativeLibraryBaseName( baseName, 32, true );
detailedNames[3] = generateDetailedNativeLibraryBaseName( baseName, 64, true );
}
}
// Construct brief and detailed native library file names.
String file = System.mapLibraryName( baseName );
String[] detailedFiles = new String[detailedNames.length];
for ( int i = 0; i < detailedNames.length; i++ )
{
if ( detailedNames[i] != null )
{
detailedFiles[i] = System.mapLibraryName( detailedNames[i] );
}
}
String[] detailedErrors = new String[detailedNames.length];
String baseError = null;
// Try loading the native library using the detailed name first. If that fails, use
// the brief name.
if ( m_debug )
{
m_out.println( "Load native library. One or more attempts may fail if platform "
+ "specific libraries do not exist." );
}
m_libraryOK = false;
for ( int i = 0; i < detailedNames.length; i++ )
{
if ( detailedNames[i] != null )
{
detailedErrors[i] = loadNativeLibrary( detailedNames[i], detailedFiles[i] );
if ( detailedErrors[i] == null )
{
m_libraryOK = true;
break;
}
}
}
if ( ( !m_libraryOK ) && ( ( baseError = loadNativeLibrary( baseName, file ) ) == null ) )
{
m_libraryOK = true;
}
if ( m_libraryOK )
{
// The library was loaded correctly, so initialize it.
if ( m_debug )
{
m_out.println( "Calling native initialization method." );
}
nativeInit( m_debug );
}
else
{
// The library could not be loaded, so we want to give the user a useful
// clue as to why not.
String libPath = System.getProperty( "java.library.path" );
m_out.println();
if ( libPath.equals( "" ) )
{
// No library path
m_out.println(
"WARNING - Unable to load the Wrapper's native library because the" );
m_out.println(
" java.library.path was set to ''. Please see the" );
m_out.println(
" documentation for the wrapper.java.library.path " );
m_out.println(
" configuration property.");
}
else
{
// Attempt to locate the actual files on the path.
String error = null;
File libFile = null;
for ( int i = 0; i < detailedNames.length; i++ )
{
if ( detailedFiles[i] != null )
{
libFile = locateFileOnPath( detailedFiles[i], libPath );
if ( libFile != null )
{
error = detailedErrors[i];
break;
}
}
}
if ( libFile == null )
{
libFile = locateFileOnPath( file, libPath );
if ( libFile != null )
{
error = baseError;
}
}
if ( libFile == null )
{
// The library could not be located on the library path.
m_out.println(
"WARNING - Unable to load the Wrapper's native library because none of the" );
m_out.println(
" following files:" );
for ( int i = 0; i < detailedNames.length; i++ )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -