Package com.biglybt.pifimpl.local.utils
Class UtilitiesImpl
- java.lang.Object
-
- com.biglybt.pifimpl.local.utils.UtilitiesImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
UtilitiesImpl.DelayedTaskImpl
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 java.lang.Exception>
static interface
UtilitiesImpl.runnableWithReturn<T>
static interface
UtilitiesImpl.runnableWithReturnAndException<T,S extends java.lang.Exception>
static interface
UtilitiesImpl.searchManager
private static class
UtilitiesImpl.TagManagerImpl
-
Nested classes/interfaces inherited from interface com.biglybt.pif.utils.Utilities
Utilities.JSONClient, Utilities.JSONServer
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description UtilitiesImpl(Core _core, PluginInterface _pi)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DelayedTask
addDelayedTask(java.lang.String name, java.lang.Runnable r)
void
addLocationProvider(LocationProvider provider)
void
addLocationProviderListener(LocationProviderListener listener)
void
addPowerManagementListener(PowerManagementListener listener)
void
addScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
static void
addSearchManager(UtilitiesImpl.searchManager manager)
java.nio.ByteBuffer
allocateDirectByteBuffer(int size)
PooledByteBuffer
allocatePooledByteBuffer(byte[] data)
PooledByteBuffer
allocatePooledByteBuffer(int length)
PooledByteBuffer
allocatePooledByteBuffer(java.util.Map map)
static <T extends java.lang.Exception>
voidcallWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithException<T> target)
static <T> T
callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturn<T> target)
static <T,S extends java.lang.Exception>
TcallWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T,S> target)
static void
callWithPluginThreadContext(PluginInterface pi, java.lang.Runnable target)
int
compareVersions(java.lang.String v1, java.lang.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 timeAggregatedList
createAggregatedList(AggregatedListAcceptor acceptor, long idle_dispatch_time, long max_queue_size)
DelayedTask
createDelayedTask(java.lang.Runnable target)
Adds a low priority task that will be scheduled at some point after existing tasks have completed.void
createProcess(java.io.File working_dirctory, java.lang.String[] command, java.lang.String[] env)
void
createProcess(java.lang.String command_line)
create a child process and executes the supplied command line.void
createThread(java.lang.String name, java.lang.Runnable target)
create and run a thread for the target.UTTimer
createTimer(java.lang.String name)
Creates aUTTimer
instance.UTTimer
createTimer(java.lang.String name, boolean lightweight)
Creates aUTTimer
instance.UTTimer
createTimer(java.lang.String name, int priority)
Creates aUTTimer
instance.UTTimer
createTimer(java.lang.String name, int max_threads, int priority)
ByteArrayWrapper
createWrapper(byte[] data)
void
deleteResilientBEncodedFile(java.io.File parent_dir, java.lang.String file_name, boolean use_backup)
void
freeDirectByteBuffer(java.nio.ByteBuffer buffer)
long
getCurrentSystemTime()
Get the current system time, like System.currentTimeMillis(), only the time lookup is cached for performance reasons.java.util.List<DistributedDatabase>
getDistributedDatabases(java.lang.String[] networks)
java.util.List<DistributedDatabase>
getDistributedDatabases(java.lang.String[] networks, java.util.Map<java.lang.String,java.lang.Object> options)
Formatters
getFormatters()
java.io.InputStream
getImageAsStream(java.lang.String image_name)
LocaleUtilities
getLocaleUtilities()
java.util.List<LocationProvider>
getLocationProviders()
Monitor
getMonitor()
static PluginInterface
getPluginThreadContext()
java.lang.String
getProgramDir()
java.net.InetAddress
getPublicAddress()
Returns a public IP address of the machine or null if it can't be determinedjava.net.InetAddress
getPublicAddress(boolean v6)
ResourceDownloaderFactory
getResourceDownloaderFactory()
ResourceUploaderFactory
getResourceUploaderFactory()
RSSFeed
getRSSFeed(java.net.URL feed_location)
RSSFeed
getRSSFeed(java.net.URL source_url, ResourceDownloader feed_location)
RSSFeed
getRSSFeed(java.net.URL source_url, java.io.InputStream is)
java.util.List<ScriptProvider>
getScriptProviders()
SearchInitiator
getSearchInitiator()
SESecurityManager
getSecurityManager()
Semaphore
getSemaphore()
SimpleXMLParserDocumentFactory
getSimpleXMLParserDocumentFactory()
SubscriptionManager
getSubscriptionManager()
TagManager
getTagManager()
java.lang.String
getUserDir()
boolean
isCVSVersion()
boolean
isFreeBSD()
boolean
isLinux()
boolean
isOSX()
boolean
isSolaris()
boolean
isUnix()
boolean
isWindows()
Tag
lookupTag(java.lang.String name)
java.lang.String
normaliseFileName(java.lang.String f_name)
Converts a file name so that all characters in the file name are compatible with the underlying filesystem.private static void
queueTask(UtilitiesImpl.DelayedTaskImpl task, int pos)
java.util.Map
readResilientBEncodedFile(java.io.File parent_dir, java.lang.String file_name, boolean use_backup)
void
registerJSONRPCClient(Utilities.JSONClient client)
void
registerJSONRPCServer(Utilities.JSONServer server)
void
registerScriptProvider(ScriptProvider provider)
void
registerSearchProvider(SearchProvider provider)
void
removeLocationProvider(LocationProvider provider)
void
removeLocationProviderListener(LocationProviderListener listener)
void
removePowerManagementListener(PowerManagementListener listener)
void
removeScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
java.lang.String
reverseDNSLookup(java.net.InetAddress address)
attempts a reverse DNS lookup of an address, null if it failsboolean
supportsPowerStateControl(int state)
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(java.io.File parent_dir, java.lang.String file_name, java.util.Map data, boolean use_backup)
-
-
-
Field Detail
-
last_public_ip_address
private static java.net.InetAddress last_public_ip_address
-
last_public_ip_address_time
private static long last_public_ip_address_time
-
core
private Core core
-
pi
private PluginInterface pi
-
tls
private static java.lang.ThreadLocal<PluginInterface> tls
-
search_managers
private static java.util.List<UtilitiesImpl.searchManager> search_managers
-
search_providers
private static java.util.List<java.lang.Object[]> search_providers
-
limiter_map
private static java.util.WeakHashMap<RateLimiter,UtilitiesImpl.PluginLimitedRateGroup> limiter_map
-
lp_listeners
private static CopyOnWriteList<LocationProviderListener> lp_listeners
-
location_providers
private static CopyOnWriteList<LocationProvider> location_providers
-
sp_listeners
private static CopyOnWriteList<ScriptProvider.ScriptProviderListener> sp_listeners
-
script_providers
private static CopyOnWriteList<ScriptProvider> script_providers
-
delayed_tasks
private static java.util.List delayed_tasks
-
delayed_tasks_sem
private static AESemaphore delayed_tasks_sem
-
delayed_task_thread
private static AEThread2 delayed_task_thread
-
json_servers
private static java.util.Map<java.lang.String,Utilities.JSONServer> json_servers
-
json_clients
private static java.util.Map<java.lang.String,Utilities.JSONClient> json_clients
-
tag_manager
private UtilitiesImpl.TagManagerImpl tag_manager
-
-
Constructor Detail
-
UtilitiesImpl
public UtilitiesImpl(Core _core, PluginInterface _pi)
-
-
Method Detail
-
wrapLimiter
public static UtilitiesImpl.PluginLimitedRateGroup wrapLimiter(RateLimiter limiter, boolean disable_disable)
-
unwrapLmiter
public static RateLimiter unwrapLmiter(UtilitiesImpl.PluginLimitedRateGroup l)
-
getUserDir
public java.lang.String getUserDir()
- Specified by:
getUserDir
in interfaceUtilities
-
getProgramDir
public java.lang.String getProgramDir()
- Specified by:
getProgramDir
in interfaceUtilities
-
isUnix
public boolean isUnix()
-
isFreeBSD
public boolean isFreeBSD()
-
isCVSVersion
public boolean isCVSVersion()
- Specified by:
isCVSVersion
in interfaceUtilities
-
getImageAsStream
public java.io.InputStream getImageAsStream(java.lang.String image_name)
- Specified by:
getImageAsStream
in interfaceUtilities
-
getSemaphore
public Semaphore getSemaphore()
- Specified by:
getSemaphore
in interfaceUtilities
-
getMonitor
public Monitor getMonitor()
- Specified by:
getMonitor
in interfaceUtilities
-
allocateDirectByteBuffer
public java.nio.ByteBuffer allocateDirectByteBuffer(int size)
- Specified by:
allocateDirectByteBuffer
in interfaceUtilities
-
freeDirectByteBuffer
public void freeDirectByteBuffer(java.nio.ByteBuffer buffer)
- Specified by:
freeDirectByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
public PooledByteBuffer allocatePooledByteBuffer(int length)
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
public PooledByteBuffer allocatePooledByteBuffer(byte[] data)
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
public PooledByteBuffer allocatePooledByteBuffer(java.util.Map map) throws java.io.IOException
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
- Parameters:
map
- must be b-encodable- Returns:
- Throws:
java.io.IOException
-
getFormatters
public Formatters getFormatters()
- Specified by:
getFormatters
in interfaceUtilities
-
getLocaleUtilities
public LocaleUtilities getLocaleUtilities()
- Specified by:
getLocaleUtilities
in interfaceUtilities
-
createTimer
public UTTimer createTimer(java.lang.String name)
Description copied from interface:Utilities
Creates aUTTimer
instance. It will be configured for non-lightweight tasks by default.- Specified by:
createTimer
in interfaceUtilities
- Parameters:
name
- Name for the UTTimer object.- Returns:
- A UTTimer instance.
-
createTimer
public UTTimer createTimer(java.lang.String name, boolean lightweight)
Description copied from interface:Utilities
Creates aUTTimer
instance.- Specified by:
createTimer
in interfaceUtilities
- Parameters:
name
- Name for the UTTimer object.lightweight
- Iftrue
, it indicates that this timer will be used to perform small lightweight tasks. Iffalse
, 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(java.lang.String name, int priority)
Description copied from interface:Utilities
Creates aUTTimer
instance.- Specified by:
createTimer
in interfaceUtilities
- Parameters:
name
- Name for the UTTimer object.priority
- The Thread.XXX_PRIORITY value to use.- Returns:
- A UTTimer instance.
-
createTimer
public UTTimer createTimer(java.lang.String name, int max_threads, int priority)
- Specified by:
createTimer
in interfaceUtilities
-
createThread
public void createThread(java.lang.String name, java.lang.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 interfaceUtilities
-
createProcess
public void createProcess(java.lang.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 interfaceUtilities
- Throws:
PluginException
-
createProcess
public void createProcess(java.io.File working_dirctory, java.lang.String[] command, java.lang.String[] env) throws PluginException
- Specified by:
createProcess
in interfaceUtilities
- Throws:
PluginException
-
getResourceDownloaderFactory
public ResourceDownloaderFactory getResourceDownloaderFactory()
- Specified by:
getResourceDownloaderFactory
in interfaceUtilities
-
getResourceUploaderFactory
public ResourceUploaderFactory getResourceUploaderFactory()
- Specified by:
getResourceUploaderFactory
in interfaceUtilities
-
getSecurityManager
public SESecurityManager getSecurityManager()
- Specified by:
getSecurityManager
in interfaceUtilities
-
getSimpleXMLParserDocumentFactory
public SimpleXMLParserDocumentFactory getSimpleXMLParserDocumentFactory()
- Specified by:
getSimpleXMLParserDocumentFactory
in interfaceUtilities
-
getRSSFeed
public RSSFeed getRSSFeed(java.net.URL source_url, java.io.InputStream is) throws SimpleXMLParserDocumentException
- Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
SimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(java.net.URL feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException
- Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(java.net.URL source_url, ResourceDownloader feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException
- Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException
-
getPublicAddress
public java.net.InetAddress getPublicAddress(boolean v6)
- Specified by:
getPublicAddress
in interfaceUtilities
-
getPublicAddress
public java.net.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 interfaceUtilities
-
reverseDNSLookup
public java.lang.String reverseDNSLookup(java.net.InetAddress address)
Description copied from interface:Utilities
attempts a reverse DNS lookup of an address, null if it fails- Specified by:
reverseDNSLookup
in interfaceUtilities
- 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 interfaceUtilities
- Returns:
- current system time
-
createWrapper
public ByteArrayWrapper createWrapper(byte[] data)
- Specified by:
createWrapper
in interfaceUtilities
-
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 interfaceUtilities
- Parameters:
idle_dispatch_time
- millisecondsmax_queue_size
- 0 -> infinite- Returns:
-
createAggregatedList
public AggregatedList createAggregatedList(AggregatedListAcceptor acceptor, long idle_dispatch_time, long max_queue_size)
- Specified by:
createAggregatedList
in interfaceUtilities
-
callWithPluginThreadContext
public static void callWithPluginThreadContext(PluginInterface pi, java.lang.Runnable target)
-
callWithPluginThreadContext
public static <T extends java.lang.Exception> void callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithException<T> target) throws T extends java.lang.Exception
- Throws:
T extends java.lang.Exception
-
callWithPluginThreadContext
public static <T> T callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturn<T> target)
-
callWithPluginThreadContext
public static <T,S extends java.lang.Exception> T callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T,S> target) throws S extends java.lang.Exception
- Throws:
S extends java.lang.Exception
-
getPluginThreadContext
public static PluginInterface getPluginThreadContext()
-
readResilientBEncodedFile
public java.util.Map readResilientBEncodedFile(java.io.File parent_dir, java.lang.String file_name, boolean use_backup)
- Specified by:
readResilientBEncodedFile
in interfaceUtilities
- Returns:
- Map read from config file, or empty HashMap if error
-
writeResilientBEncodedFile
public void writeResilientBEncodedFile(java.io.File parent_dir, java.lang.String file_name, java.util.Map data, boolean use_backup)
- Specified by:
writeResilientBEncodedFile
in interfaceUtilities
-
deleteResilientBEncodedFile
public void deleteResilientBEncodedFile(java.io.File parent_dir, java.lang.String file_name, boolean use_backup)
- Specified by:
deleteResilientBEncodedFile
in interfaceUtilities
-
compareVersions
public int compareVersions(java.lang.String v1, java.lang.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 interfaceUtilities
- Parameters:
v1
- the first version string to be comparedv2
- 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 java.lang.String normaliseFileName(java.lang.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 interfaceUtilities
- Parameters:
f_name
- File name to convert.- Returns:
- Converted file name.
-
createDelayedTask
public DelayedTask createDelayedTask(java.lang.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 interfaceUtilities
- Returns:
-
addDelayedTask
public static DelayedTask addDelayedTask(java.lang.String name, java.lang.Runnable r)
-
queueTask
private static void queueTask(UtilitiesImpl.DelayedTaskImpl task, int pos)
-
registerSearchProvider
public void registerSearchProvider(SearchProvider provider) throws SearchException
- Specified by:
registerSearchProvider
in interfaceUtilities
- Throws:
SearchException
-
unregisterSearchProvider
public void unregisterSearchProvider(SearchProvider provider) throws SearchException
- Specified by:
unregisterSearchProvider
in interfaceUtilities
- Throws:
SearchException
-
getSearchInitiator
public SearchInitiator getSearchInitiator() throws SearchException
- Specified by:
getSearchInitiator
in interfaceUtilities
- Throws:
SearchException
-
addSearchManager
public static void addSearchManager(UtilitiesImpl.searchManager manager)
-
getSubscriptionManager
public SubscriptionManager getSubscriptionManager() throws SubscriptionException
- Specified by:
getSubscriptionManager
in interfaceUtilities
- Throws:
SubscriptionException
-
supportsPowerStateControl
public boolean supportsPowerStateControl(int state)
- Specified by:
supportsPowerStateControl
in interfaceUtilities
-
addPowerManagementListener
public void addPowerManagementListener(PowerManagementListener listener)
- Specified by:
addPowerManagementListener
in interfaceUtilities
-
removePowerManagementListener
public void removePowerManagementListener(PowerManagementListener listener)
- Specified by:
removePowerManagementListener
in interfaceUtilities
-
getLocationProviders
public java.util.List<LocationProvider> getLocationProviders()
- Specified by:
getLocationProviders
in interfaceUtilities
-
addLocationProvider
public void addLocationProvider(LocationProvider provider)
- Specified by:
addLocationProvider
in interfaceUtilities
-
removeLocationProvider
public void removeLocationProvider(LocationProvider provider)
- Specified by:
removeLocationProvider
in interfaceUtilities
-
addLocationProviderListener
public void addLocationProviderListener(LocationProviderListener listener)
- Specified by:
addLocationProviderListener
in interfaceUtilities
-
removeLocationProviderListener
public void removeLocationProviderListener(LocationProviderListener listener)
- Specified by:
removeLocationProviderListener
in interfaceUtilities
-
getScriptProviders
public java.util.List<ScriptProvider> getScriptProviders()
- Specified by:
getScriptProviders
in interfaceUtilities
-
registerScriptProvider
public void registerScriptProvider(ScriptProvider provider)
- Specified by:
registerScriptProvider
in interfaceUtilities
-
unregisterScriptProvider
public void unregisterScriptProvider(ScriptProvider provider)
- Specified by:
unregisterScriptProvider
in interfaceUtilities
-
addScriptProviderListener
public void addScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
- Specified by:
addScriptProviderListener
in interfaceUtilities
-
removeScriptProviderListener
public void removeScriptProviderListener(ScriptProvider.ScriptProviderListener listener)
- Specified by:
removeScriptProviderListener
in interfaceUtilities
-
lookupTag
public Tag lookupTag(java.lang.String name)
-
getDistributedDatabases
public java.util.List<DistributedDatabase> getDistributedDatabases(java.lang.String[] networks)
- Specified by:
getDistributedDatabases
in interfaceUtilities
-
getDistributedDatabases
public java.util.List<DistributedDatabase> getDistributedDatabases(java.lang.String[] networks, java.util.Map<java.lang.String,java.lang.Object> options)
- Specified by:
getDistributedDatabases
in interfaceUtilities
-
registerJSONRPCServer
public void registerJSONRPCServer(Utilities.JSONServer server)
- Specified by:
registerJSONRPCServer
in interfaceUtilities
-
unregisterJSONRPCServer
public void unregisterJSONRPCServer(Utilities.JSONServer server)
- Specified by:
unregisterJSONRPCServer
in interfaceUtilities
-
registerJSONRPCClient
public void registerJSONRPCClient(Utilities.JSONClient client)
- Specified by:
registerJSONRPCClient
in interfaceUtilities
-
unregisterJSONRPCClient
public void unregisterJSONRPCClient(Utilities.JSONClient client)
- Specified by:
unregisterJSONRPCClient
in interfaceUtilities
-
getTagManager
public TagManager getTagManager()
- Specified by:
getTagManager
in interfaceUtilities
-
-