org.gudy.azureus2.pluginsimpl.local.utils
Class UtilitiesImpl

java.lang.Object
  extended by org.gudy.azureus2.pluginsimpl.local.utils.UtilitiesImpl
All Implemented Interfaces:
FeatureManager, Utilities

public class UtilitiesImpl
extends Object
implements Utilities, FeatureManager


Nested Class Summary
static class UtilitiesImpl.PluginLimitedRateGroup
           
static interface UtilitiesImpl.PluginLimitedRateGroupListener
           
static interface UtilitiesImpl.PluginSubscription
           
static interface UtilitiesImpl.PluginSubscriptionManager
           
static interface UtilitiesImpl.PluginSubscriptionResult
           
static interface UtilitiesImpl.runnableWithException<T extends Exception>
           
static interface UtilitiesImpl.runnableWithReturn<T>
           
static interface UtilitiesImpl.runnableWithReturnAndException<T,S extends Exception>
           
static interface UtilitiesImpl.searchManager
           
 
Nested classes/interfaces inherited from interface org.gudy.azureus2.plugins.utils.Utilities
Utilities.JSONClient, Utilities.JSONServer
 
Nested classes/interfaces inherited from interface org.gudy.azureus2.plugins.utils.FeatureManager
FeatureManager.FeatureDetails, FeatureManager.FeatureEnabler, FeatureManager.FeatureManagerListener, FeatureManager.Licence
 
Constructor Summary
UtilitiesImpl(AzureusCore _core, PluginInterface _pi)
           
 
Method Summary
static DelayedTask addDelayedTask(String name, Runnable r)
           
 FeatureManager.Licence addLicence(String licence_key)
           
 void addListener(FeatureManager.FeatureManagerListener listener)
           
 void addLocationProvider(LocationProvider provider)
           
 void addLocationProviderListener(LocationProviderListener listener)
           
 void addPowerManagementListener(PowerManagementListener listener)
           
 void addScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
           
static void addSearchManager(UtilitiesImpl.searchManager manager)
           
 ByteBuffer allocateDirectByteBuffer(int size)
           
 PooledByteBuffer allocatePooledByteBuffer(byte[] data)
           
 PooledByteBuffer allocatePooledByteBuffer(int length)
           
 PooledByteBuffer allocatePooledByteBuffer(Map map)
           
static void callWithPluginThreadContext(PluginInterface pi, Runnable target)
           
static
<T extends Exception>
void
callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithException<T> target)
           
static
<T> T
callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturn<T> target)
           
static
<T,S extends Exception>
T
callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T,S> target)
           
 int compareVersions(String v1, String v2)
          Compares two version strings for order.
 AggregatedDispatcher createAggregatedDispatcher(long idle_dispatch_time, long max_queue_size)
          create a dispatcher that will queue runnable items until either the limit is reached or the dispatcher hasn't had an entry added for the defined idle time
 AggregatedList createAggregatedList(AggregatedListAcceptor acceptor, long idle_dispatch_time, long max_queue_size)
           
 DelayedTask createDelayedTask(Runnable target)
          Adds a low priority task that will be scheduled at some point after existing tasks have completed.
 FeatureManager.Licence[] createLicences(String[] feature_ids)
           
 void createProcess(String command_line)
          create a child process and executes the supplied command line.
 void createThread(String name, Runnable target)
          create and run a thread for the target.
 UTTimer createTimer(String name)
          Creates a UTTimer instance.
 UTTimer createTimer(String name, boolean lightweight)
          Creates a UTTimer instance.
 UTTimer createTimer(String name, int priority)
          Creates a UTTimer instance.
 ByteArrayWrapper createWrapper(byte[] data)
           
 void deleteResilientBEncodedFile(File parent_dir, String file_name, boolean use_backup)
           
 void freeDirectByteBuffer(ByteBuffer buffer)
           
 String getAzureusProgramDir()
           
 String getAzureusUserDir()
           
 long getCurrentSystemTime()
          Get the current system time, like System.currentTimeMillis(), only the time lookup is cached for performance reasons.
 List<DistributedDatabase> getDistributedDatabases(String[] networks)
           
 List<DistributedDatabase> getDistributedDatabases(String[] networks, Map<String,Object> options)
           
 FeatureManager.FeatureDetails[] getFeatureDetails(String feature_id)
           
 FeatureManager getFeatureManager()
           
static Set<String> getFeaturesInstalled()
           
 Formatters getFormatters()
           
 InputStream getImageAsStream(String image_name)
           
 FeatureManager.Licence[] getLicences()
           
 LocaleUtilities getLocaleUtilities()
           
 List<LocationProvider> getLocationProviders()
           
 Monitor getMonitor()
           
static PluginInterface getPluginThreadContext()
           
 InetAddress getPublicAddress()
          Returns a public IP address of the machine or null if it can't be determined
 InetAddress getPublicAddress(boolean v6)
           
 ResourceDownloaderFactory getResourceDownloaderFactory()
           
 ResourceUploaderFactory getResourceUploaderFactory()
           
 RSSFeed getRSSFeed(InputStream is)
           
 RSSFeed getRSSFeed(ResourceDownloader feed_location)
           
 RSSFeed getRSSFeed(URL feed_location)
           
 RSSFeed getRSSFeed(URL source_url, InputStream is)
           
 RSSFeed getRSSFeed(URL source_url, ResourceDownloader feed_location)
           
 List<ScriptProvider> getScriptProviders()
           
 SearchInitiator getSearchInitiator()
           
 SESecurityManager getSecurityManager()
           
 Semaphore getSemaphore()
           
 SimpleXMLParserDocumentFactory getSimpleXMLParserDocumentFactory()
           
 SubscriptionManager getSubscriptionManager()
           
 TagManager getTagManager()
           
 boolean isCVSVersion()
           
 boolean isFeatureInstalled(String feature_id)
           
 boolean isFreeBSD()
           
 boolean isLinux()
           
 boolean isOSX()
           
 boolean isSolaris()
           
 boolean isUnix()
           
 boolean isWindows()
           
 Tag lookupTag(String name)
           
 String normaliseFileName(String f_name)
          Converts a file name so that all characters in the file name are compatible with the underlying filesystem.
 Map readResilientBEncodedFile(File parent_dir, String file_name, boolean use_backup)
           
 void refreshLicences()
           
 void registerFeatureEnabler(FeatureManager.FeatureEnabler enabler)
           
 void registerJSONRPCClient(Utilities.JSONClient client)
           
 void registerJSONRPCServer(Utilities.JSONServer server)
           
 void registerScriptProvider(ScriptProvider provider)
           
 void registerSearchProvider(SearchProvider provider)
           
 void removeListener(FeatureManager.FeatureManagerListener listener)
           
 void removeLocationProvider(LocationProvider provider)
           
 void removeLocationProviderListener(LocationProviderListener listener)
           
 void removePowerManagementListener(PowerManagementListener listener)
           
 void removeScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
           
 String reverseDNSLookup(InetAddress address)
          attempts a reverse DNS lookup of an address, null if it fails
 boolean supportsPowerStateControl(int state)
           
 void unregisterFeatureEnabler(FeatureManager.FeatureEnabler enabler)
           
 void unregisterJSONRPCClient(Utilities.JSONClient client)
           
 void unregisterJSONRPCServer(Utilities.JSONServer server)
           
 void unregisterScriptProvider(ScriptProvider provider)
           
 void unregisterSearchProvider(SearchProvider provider)
           
static RateLimiter unwrapLmiter(UtilitiesImpl.PluginLimitedRateGroup l)
           
static UtilitiesImpl.PluginLimitedRateGroup wrapLimiter(RateLimiter limiter, boolean disable_disable)
           
 void writeResilientBEncodedFile(File parent_dir, String file_name, Map data, boolean use_backup)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilitiesImpl

public UtilitiesImpl(AzureusCore _core,
                     PluginInterface _pi)
Method Detail

wrapLimiter

public static UtilitiesImpl.PluginLimitedRateGroup wrapLimiter(RateLimiter limiter,
                                                               boolean disable_disable)

unwrapLmiter

public static RateLimiter unwrapLmiter(UtilitiesImpl.PluginLimitedRateGroup l)

getFeaturesInstalled

public static Set<String> getFeaturesInstalled()

getAzureusUserDir

public String getAzureusUserDir()
Specified by:
getAzureusUserDir in interface Utilities

getAzureusProgramDir

public String getAzureusProgramDir()
Specified by:
getAzureusProgramDir in interface Utilities

isWindows

public boolean isWindows()
Specified by:
isWindows in interface Utilities

isLinux

public boolean isLinux()
Specified by:
isLinux in interface Utilities

isUnix

public boolean isUnix()
Specified by:
isUnix in interface Utilities
Returns:
Whether the OS is a unix flavor (linux, bsd, aix, etc)

isFreeBSD

public boolean isFreeBSD()
Specified by:
isFreeBSD in interface Utilities
Returns:
Whether the OS is FreeBSD

isSolaris

public boolean isSolaris()
Specified by:
isSolaris in interface Utilities

isOSX

public boolean isOSX()
Specified by:
isOSX in interface Utilities

isCVSVersion

public boolean isCVSVersion()
Specified by:
isCVSVersion in interface Utilities

getImageAsStream

public InputStream getImageAsStream(String image_name)
Specified by:
getImageAsStream in interface Utilities

getSemaphore

public Semaphore getSemaphore()
Specified by:
getSemaphore in interface Utilities

getMonitor

public Monitor getMonitor()
Specified by:
getMonitor in interface Utilities

allocateDirectByteBuffer

public ByteBuffer allocateDirectByteBuffer(int size)
Specified by:
allocateDirectByteBuffer in interface Utilities

freeDirectByteBuffer

public void freeDirectByteBuffer(ByteBuffer buffer)
Specified by:
freeDirectByteBuffer in interface Utilities

allocatePooledByteBuffer

public PooledByteBuffer allocatePooledByteBuffer(int length)
Specified by:
allocatePooledByteBuffer in interface Utilities

allocatePooledByteBuffer

public PooledByteBuffer allocatePooledByteBuffer(byte[] data)
Specified by:
allocatePooledByteBuffer in interface Utilities

allocatePooledByteBuffer

public PooledByteBuffer allocatePooledByteBuffer(Map map)
                                          throws IOException
Specified by:
allocatePooledByteBuffer in interface Utilities
Parameters:
map - must be b-encodable
Returns:
Throws:
IOException

getFormatters

public Formatters getFormatters()
Specified by:
getFormatters in interface Utilities

getLocaleUtilities

public LocaleUtilities getLocaleUtilities()
Specified by:
getLocaleUtilities in interface Utilities

createTimer

public UTTimer createTimer(String name)
Description copied from interface: Utilities
Creates a UTTimer instance. It will be configured for non-lightweight tasks by default.

Specified by:
createTimer in interface Utilities
Parameters:
name - Name for the UTTimer object.
Returns:
A UTTimer instance.

createTimer

public UTTimer createTimer(String name,
                           boolean lightweight)
Description copied from interface: Utilities
Creates a UTTimer instance.

Specified by:
createTimer in interface Utilities
Parameters:
name - Name for the UTTimer object.
lightweight - If true, it indicates that this timer will be used to perform small lightweight tasks. If false, it indicates that this timer will be used to perform expensive tasks. This allows Azureus to create the appropriate amount of resources to manage this timer.
Returns:
A UTTimer instance.

createTimer

public UTTimer createTimer(String name,
                           int priority)
Description copied from interface: Utilities
Creates a UTTimer instance.

Specified by:
createTimer in interface Utilities
Parameters:
name - Name for the UTTimer object.
priority - The Thread.XXX_PRIORITY value to use.
Returns:
A UTTimer instance.

createThread

public void createThread(String name,
                         Runnable target)
Description copied from interface: Utilities
create and run a thread for the target. This will be a daemon thread so that its existence doesn't interfere with Azureus closedown

Specified by:
createThread in interface Utilities

createProcess

public void createProcess(String command_line)
                   throws PluginException
Description copied from interface: Utilities
create a child process and executes the supplied command line. The child process will not inherit any open handles on Windows, which does happen if Runtime is used directly. This relies on the Platform plugin, if this is not installed then this will fall back to using Runtime.exec

Specified by:
createProcess in interface Utilities
Throws:
PluginException

getResourceDownloaderFactory

public ResourceDownloaderFactory getResourceDownloaderFactory()
Specified by:
getResourceDownloaderFactory in interface Utilities

getResourceUploaderFactory

public ResourceUploaderFactory getResourceUploaderFactory()
Specified by:
getResourceUploaderFactory in interface Utilities

getSecurityManager

public SESecurityManager getSecurityManager()
Specified by:
getSecurityManager in interface Utilities

getSimpleXMLParserDocumentFactory

public SimpleXMLParserDocumentFactory getSimpleXMLParserDocumentFactory()
Specified by:
getSimpleXMLParserDocumentFactory in interface Utilities

getRSSFeed

public RSSFeed getRSSFeed(InputStream is)
                   throws SimpleXMLParserDocumentException
Specified by:
getRSSFeed in interface Utilities
Returns:
Throws:
SimpleXMLParserDocumentException

getRSSFeed

public RSSFeed getRSSFeed(URL source_url,
                          InputStream is)
                   throws SimpleXMLParserDocumentException
Specified by:
getRSSFeed in interface Utilities
Throws:
SimpleXMLParserDocumentException

getRSSFeed

public RSSFeed getRSSFeed(URL feed_location)
                   throws ResourceDownloaderException,
                          SimpleXMLParserDocumentException
Specified by:
getRSSFeed in interface Utilities
Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException

getRSSFeed

public RSSFeed getRSSFeed(ResourceDownloader feed_location)
                   throws ResourceDownloaderException,
                          SimpleXMLParserDocumentException
Specified by:
getRSSFeed in interface Utilities
Returns:
Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException

getRSSFeed

public RSSFeed getRSSFeed(URL source_url,
                          ResourceDownloader feed_location)
                   throws ResourceDownloaderException,
                          SimpleXMLParserDocumentException
Specified by:
getRSSFeed in interface Utilities
Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException

getPublicAddress

public InetAddress getPublicAddress(boolean v6)
Specified by:
getPublicAddress in interface Utilities

getPublicAddress

public InetAddress getPublicAddress()
Description copied from interface: Utilities
Returns a public IP address of the machine or null if it can't be determined

Specified by:
getPublicAddress in interface Utilities

reverseDNSLookup

public String reverseDNSLookup(InetAddress address)
Description copied from interface: Utilities
attempts a reverse DNS lookup of an address, null if it fails

Specified by:
reverseDNSLookup in interface Utilities
Returns:

getCurrentSystemTime

public long getCurrentSystemTime()
Description copied from interface: Utilities
Get the current system time, like System.currentTimeMillis(), only the time lookup is cached for performance reasons.

Specified by:
getCurrentSystemTime in interface Utilities
Returns:
current system time

createWrapper

public ByteArrayWrapper createWrapper(byte[] data)
Specified by:
createWrapper in interface Utilities

createAggregatedDispatcher

public AggregatedDispatcher createAggregatedDispatcher(long idle_dispatch_time,
                                                       long max_queue_size)
Description copied from interface: Utilities
create a dispatcher that will queue runnable items until either the limit is reached or the dispatcher hasn't had an entry added for the defined idle time

Specified by:
createAggregatedDispatcher in interface Utilities
Parameters:
idle_dispatch_time - milliseconds
max_queue_size - 0 -> infinite
Returns:

createAggregatedList

public AggregatedList createAggregatedList(AggregatedListAcceptor acceptor,
                                           long idle_dispatch_time,
                                           long max_queue_size)
Specified by:
createAggregatedList in interface Utilities

callWithPluginThreadContext

public static final void callWithPluginThreadContext(PluginInterface pi,
                                                     Runnable target)

callWithPluginThreadContext

public static final <T extends Exception> void callWithPluginThreadContext(PluginInterface pi,
                                                                           UtilitiesImpl.runnableWithException<T> target)
                                              throws T extends Exception
Throws:
T extends Exception

callWithPluginThreadContext

public static final <T> T callWithPluginThreadContext(PluginInterface pi,
                                                      UtilitiesImpl.runnableWithReturn<T> target)

callWithPluginThreadContext

public static final <T,S extends Exception> T callWithPluginThreadContext(PluginInterface pi,
                                                                          UtilitiesImpl.runnableWithReturnAndException<T,S> target)
                                           throws S extends Exception
Throws:
S extends Exception

getPluginThreadContext

public static PluginInterface getPluginThreadContext()

readResilientBEncodedFile

public Map readResilientBEncodedFile(File parent_dir,
                                     String file_name,
                                     boolean use_backup)
Specified by:
readResilientBEncodedFile in interface Utilities
Returns:
Map read from config file, or empty HashMap if error

writeResilientBEncodedFile

public void writeResilientBEncodedFile(File parent_dir,
                                       String file_name,
                                       Map data,
                                       boolean use_backup)
Specified by:
writeResilientBEncodedFile in interface Utilities

deleteResilientBEncodedFile

public void deleteResilientBEncodedFile(File parent_dir,
                                        String file_name,
                                        boolean use_backup)
Specified by:
deleteResilientBEncodedFile in interface Utilities

compareVersions

public int compareVersions(String v1,
                           String v2)
Description copied from interface: Utilities
Compares two version strings for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Example:

 compareVersions("1.1.0.0", "1.1.2.0"); // -
 compareVersions("1.1.0.0", "1.1.0"); // 0
 compareVersions("1.1.1.1", "1.1.1"); // +
 

Specified by:
compareVersions in interface Utilities
Parameters:
v1 - the first version string to be compared
v2 - the second version string to be compared
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

normaliseFileName

public String normaliseFileName(String f_name)
Description copied from interface: Utilities
Converts a file name so that all characters in the file name are compatible with the underlying filesystem. This includes quote characters, back and forwarded slashes, newline characters and so on.

Note - this is only intended for file names, rather than file paths.

Specified by:
normaliseFileName in interface Utilities
Parameters:
f_name - File name to convert.
Returns:
Converted file name.

createDelayedTask

public DelayedTask createDelayedTask(Runnable target)
Description copied from interface: Utilities
Adds a low priority task that will be scheduled at some point after existing tasks have completed. In particular a system task exists that will block subsequent ones until after UI initialisation is complete. Plugins can therefore use this to schedule initialisation actions to occur after UI init is complete.

Specified by:
createDelayedTask in interface Utilities
Returns:

addDelayedTask

public static DelayedTask addDelayedTask(String name,
                                         Runnable r)

registerSearchProvider

public void registerSearchProvider(SearchProvider provider)
                            throws SearchException
Specified by:
registerSearchProvider in interface Utilities
Throws:
SearchException

unregisterSearchProvider

public void unregisterSearchProvider(SearchProvider provider)
                              throws SearchException
Specified by:
unregisterSearchProvider in interface Utilities
Throws:
SearchException

getSearchInitiator

public SearchInitiator getSearchInitiator()
                                   throws SearchException
Specified by:
getSearchInitiator in interface Utilities
Throws:
SearchException

addSearchManager

public static void addSearchManager(UtilitiesImpl.searchManager manager)

getFeatureManager

public FeatureManager getFeatureManager()
Specified by:
getFeatureManager in interface Utilities

createLicences

public FeatureManager.Licence[] createLicences(String[] feature_ids)
                                        throws PluginException
Specified by:
createLicences in interface FeatureManager
Throws:
PluginException

addLicence

public FeatureManager.Licence addLicence(String licence_key)
                                  throws PluginException
Specified by:
addLicence in interface FeatureManager
Throws:
PluginException

getLicences

public FeatureManager.Licence[] getLicences()
Specified by:
getLicences in interface FeatureManager

refreshLicences

public void refreshLicences()
Specified by:
refreshLicences in interface FeatureManager

getFeatureDetails

public FeatureManager.FeatureDetails[] getFeatureDetails(String feature_id)
Specified by:
getFeatureDetails in interface FeatureManager

isFeatureInstalled

public boolean isFeatureInstalled(String feature_id)
Specified by:
isFeatureInstalled in interface FeatureManager

addListener

public void addListener(FeatureManager.FeatureManagerListener listener)
Specified by:
addListener in interface FeatureManager

removeListener

public void removeListener(FeatureManager.FeatureManagerListener listener)
Specified by:
removeListener in interface FeatureManager

registerFeatureEnabler

public void registerFeatureEnabler(FeatureManager.FeatureEnabler enabler)
Specified by:
registerFeatureEnabler in interface FeatureManager

unregisterFeatureEnabler

public void unregisterFeatureEnabler(FeatureManager.FeatureEnabler enabler)
Specified by:
unregisterFeatureEnabler in interface FeatureManager

getSubscriptionManager

public SubscriptionManager getSubscriptionManager()
                                           throws SubscriptionException
Specified by:
getSubscriptionManager in interface Utilities
Throws:
SubscriptionException

supportsPowerStateControl

public boolean supportsPowerStateControl(int state)
Specified by:
supportsPowerStateControl in interface Utilities

addPowerManagementListener

public void addPowerManagementListener(PowerManagementListener listener)
Specified by:
addPowerManagementListener in interface Utilities

removePowerManagementListener

public void removePowerManagementListener(PowerManagementListener listener)
Specified by:
removePowerManagementListener in interface Utilities

getLocationProviders

public List<LocationProvider> getLocationProviders()
Specified by:
getLocationProviders in interface Utilities

addLocationProvider

public void addLocationProvider(LocationProvider provider)
Specified by:
addLocationProvider in interface Utilities

removeLocationProvider

public void removeLocationProvider(LocationProvider provider)
Specified by:
removeLocationProvider in interface Utilities

addLocationProviderListener

public void addLocationProviderListener(LocationProviderListener listener)
Specified by:
addLocationProviderListener in interface Utilities

removeLocationProviderListener

public void removeLocationProviderListener(LocationProviderListener listener)
Specified by:
removeLocationProviderListener in interface Utilities

getScriptProviders

public List<ScriptProvider> getScriptProviders()
Specified by:
getScriptProviders in interface Utilities

registerScriptProvider

public void registerScriptProvider(ScriptProvider provider)
Specified by:
registerScriptProvider in interface Utilities

unregisterScriptProvider

public void unregisterScriptProvider(ScriptProvider provider)
Specified by:
unregisterScriptProvider in interface Utilities

addScriptProviderListener

public void addScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
Specified by:
addScriptProviderListener in interface Utilities

removeScriptProviderListener

public void removeScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
Specified by:
removeScriptProviderListener in interface Utilities

lookupTag

public Tag lookupTag(String name)
Specified by:
lookupTag in interface Utilities

getDistributedDatabases

public List<DistributedDatabase> getDistributedDatabases(String[] networks)
Specified by:
getDistributedDatabases in interface Utilities

getDistributedDatabases

public List<DistributedDatabase> getDistributedDatabases(String[] networks,
                                                         Map<String,Object> options)
Specified by:
getDistributedDatabases in interface Utilities

registerJSONRPCServer

public void registerJSONRPCServer(Utilities.JSONServer server)
Specified by:
registerJSONRPCServer in interface Utilities

unregisterJSONRPCServer

public void unregisterJSONRPCServer(Utilities.JSONServer server)
Specified by:
unregisterJSONRPCServer in interface Utilities

registerJSONRPCClient

public void registerJSONRPCClient(Utilities.JSONClient client)
Specified by:
registerJSONRPCClient in interface Utilities

unregisterJSONRPCClient

public void unregisterJSONRPCClient(Utilities.JSONClient client)
Specified by:
unregisterJSONRPCClient in interface Utilities

getTagManager

public TagManager getTagManager()
Specified by:
getTagManager in interface Utilities