Package com.biglybt.pifimpl.local.utils
Class UtilitiesImpl
java.lang.Object
com.biglybt.pifimpl.local.utils.UtilitiesImpl
- All Implemented Interfaces:
Utilities
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
static class
static interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
private static class
Nested classes/interfaces inherited from interface com.biglybt.pif.utils.Utilities
Utilities.JSONClient, Utilities.JSONServer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Core
private static AEThread2
private static List
private static AESemaphore
private static Map
<String, Utilities.JSONClient> private static Map
<String, Utilities.JSONServer> private static InetAddress
private static long
private static WeakHashMap
<RateLimiter, UtilitiesImpl.PluginLimitedRateGroup> private static CopyOnWriteList
<LocationProvider> private static CopyOnWriteList
<LocationProviderListener> private PluginInterface
private static CopyOnWriteList
<ScriptProvider> private static List
<UtilitiesImpl.searchManager> private static CopyOnWriteList
<ScriptProvider.ScriptProviderListener> private UtilitiesImpl.TagManagerImpl
private static ThreadLocal
<PluginInterface> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DelayedTask
addDelayedTask
(String name, Runnable r) void
addLocationProvider
(LocationProvider provider) void
void
void
static void
allocateDirectByteBuffer
(int size) allocatePooledByteBuffer
(byte[] data) allocatePooledByteBuffer
(int length) static <T extends Exception>
voidstatic <T> T
static <T,
S extends Exception>
TcallWithPluginThreadContext
(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T, S> target) static void
callWithPluginThreadContext
(PluginInterface pi, Runnable target) int
compareVersions
(String v1, String v2) Compares two version strings for order.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 timecreateAggregatedList
(AggregatedListAcceptor acceptor, long idle_dispatch_time, long max_queue_size) createDelayedTask
(Runnable target) Adds a low priority task that will be scheduled at some point after existing tasks have completed.void
createProcess
(File working_dirctory, String[] command, String[] env) 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.createTimer
(String name) Creates aUTTimer
instance.createTimer
(String name, boolean lightweight) Creates aUTTimer
instance.createTimer
(String name, int priority) Creates aUTTimer
instance.createTimer
(String name, int max_threads, int priority) createWrapper
(byte[] data) void
deleteResilientBEncodedFile
(File parent_dir, String file_name, boolean use_backup) void
freeDirectByteBuffer
(ByteBuffer buffer) long
Get the current system time, like System.currentTimeMillis(), only the time lookup is cached for performance reasons.getDistributedDatabases
(String[] networks) getDistributedDatabases
(String[] networks, Map<String, Object> options) getImageAsStream
(String image_name) static PluginInterface
Returns a public IP address of the machine or null if it can't be determinedgetPublicAddress
(boolean v6) getRSSFeed
(URL feed_location) getRSSFeed
(URL source_url, ResourceDownloader feed_location) getRSSFeed
(URL source_url, InputStream is) boolean
boolean
boolean
isLinux()
boolean
isOSX()
boolean
boolean
isUnix()
boolean
normaliseFileName
(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) readResilientBEncodedFile
(File parent_dir, String file_name, boolean use_backup) void
void
void
registerScriptProvider
(ScriptProvider provider) void
registerSearchProvider
(SearchProvider provider) void
removeLocationProvider
(LocationProvider provider) void
void
void
reverseDNSLookup
(InetAddress address) attempts a reverse DNS lookup of an address, null if it failsboolean
supportsPowerStateControl
(int state) void
void
void
unregisterScriptProvider
(ScriptProvider provider) void
unregisterSearchProvider
(SearchProvider provider) static RateLimiter
wrapLimiter
(RateLimiter limiter, boolean disable_disable) void
writeResilientBEncodedFile
(File parent_dir, String file_name, Map data, boolean use_backup)
-
Field Details
-
last_public_ip_address
-
last_public_ip_address_time
private static long last_public_ip_address_time -
core
-
pi
-
tls
-
search_managers
-
search_providers
-
limiter_map
-
lp_listeners
-
location_providers
-
sp_listeners
-
script_providers
-
delayed_tasks
-
delayed_tasks_sem
-
delayed_task_thread
-
json_servers
-
json_clients
-
tag_manager
-
-
Constructor Details
-
UtilitiesImpl
-
-
Method Details
-
wrapLimiter
public static UtilitiesImpl.PluginLimitedRateGroup wrapLimiter(RateLimiter limiter, boolean disable_disable) -
unwrapLmiter
-
getUserDir
- Specified by:
getUserDir
in interfaceUtilities
-
getProgramDir
- Specified by:
getProgramDir
in interfaceUtilities
-
isWindows
public boolean isWindows() -
isLinux
public boolean isLinux() -
isUnix
public boolean isUnix() -
isFreeBSD
public boolean isFreeBSD() -
isSolaris
public boolean isSolaris() -
isOSX
public boolean isOSX() -
isCVSVersion
public boolean isCVSVersion()- Specified by:
isCVSVersion
in interfaceUtilities
-
getImageAsStream
- Specified by:
getImageAsStream
in interfaceUtilities
-
getSemaphore
- Specified by:
getSemaphore
in interfaceUtilities
-
getMonitor
- Specified by:
getMonitor
in interfaceUtilities
-
allocateDirectByteBuffer
- Specified by:
allocateDirectByteBuffer
in interfaceUtilities
-
freeDirectByteBuffer
- Specified by:
freeDirectByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBuffer
in interfaceUtilities
- Parameters:
map
- must be b-encodable- Returns:
- Throws:
IOException
-
getFormatters
- Specified by:
getFormatters
in interfaceUtilities
-
getLocaleUtilities
- Specified by:
getLocaleUtilities
in interfaceUtilities
-
createTimer
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
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
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
- Specified by:
createTimer
in interfaceUtilities
-
createThread
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
- Parameters:
name
-target
-
-
createProcess
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
- Parameters:
command_line
-- Throws:
PluginException
-
createProcess
public void createProcess(File working_dirctory, String[] command, String[] env) throws PluginException - Specified by:
createProcess
in interfaceUtilities
- Throws:
PluginException
-
getResourceDownloaderFactory
- Specified by:
getResourceDownloaderFactory
in interfaceUtilities
-
getResourceUploaderFactory
- Specified by:
getResourceUploaderFactory
in interfaceUtilities
-
getSecurityManager
- Specified by:
getSecurityManager
in interfaceUtilities
-
getSimpleXMLParserDocumentFactory
- Specified by:
getSimpleXMLParserDocumentFactory
in interfaceUtilities
-
getRSSFeed
- Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
SimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(URL feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException - Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(URL source_url, ResourceDownloader feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException - Specified by:
getRSSFeed
in interfaceUtilities
- Throws:
ResourceDownloaderException
SimpleXMLParserDocumentException
-
getPublicAddress
- Specified by:
getPublicAddress
in interfaceUtilities
-
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
Description copied from interface:Utilities
attempts a reverse DNS lookup of an address, null if it fails- Specified by:
reverseDNSLookup
in interfaceUtilities
- Parameters:
address
-- 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
- 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
-
callWithPluginThreadContext
public static <T extends Exception> void callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithException<T> target) throws T - Throws:
T
-
callWithPluginThreadContext
public static <T> T callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturn<T> target) -
callWithPluginThreadContext
public static <T,S extends Exception> T callWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T, S> target) throws S- Throws:
S
-
getPluginThreadContext
-
readResilientBEncodedFile
- Specified by:
readResilientBEncodedFile
in interfaceUtilities
- 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 interfaceUtilities
-
deleteResilientBEncodedFile
- Specified by:
deleteResilientBEncodedFile
in interfaceUtilities
-
compareVersions
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
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
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
-
queueTask
-
registerSearchProvider
- Specified by:
registerSearchProvider
in interfaceUtilities
- Throws:
SearchException
-
unregisterSearchProvider
- Specified by:
unregisterSearchProvider
in interfaceUtilities
- Throws:
SearchException
-
getSearchInitiator
- Specified by:
getSearchInitiator
in interfaceUtilities
- Throws:
SearchException
-
addSearchManager
-
getSubscriptionManager
- Specified by:
getSubscriptionManager
in interfaceUtilities
- Throws:
SubscriptionException
-
supportsPowerStateControl
public boolean supportsPowerStateControl(int state) - Specified by:
supportsPowerStateControl
in interfaceUtilities
-
addPowerManagementListener
- Specified by:
addPowerManagementListener
in interfaceUtilities
-
removePowerManagementListener
- Specified by:
removePowerManagementListener
in interfaceUtilities
-
getLocationProviders
- Specified by:
getLocationProviders
in interfaceUtilities
-
addLocationProvider
- Specified by:
addLocationProvider
in interfaceUtilities
-
removeLocationProvider
- Specified by:
removeLocationProvider
in interfaceUtilities
-
addLocationProviderListener
- Specified by:
addLocationProviderListener
in interfaceUtilities
-
removeLocationProviderListener
- Specified by:
removeLocationProviderListener
in interfaceUtilities
-
getScriptProviders
- Specified by:
getScriptProviders
in interfaceUtilities
-
registerScriptProvider
- Specified by:
registerScriptProvider
in interfaceUtilities
-
unregisterScriptProvider
- Specified by:
unregisterScriptProvider
in interfaceUtilities
-
addScriptProviderListener
- Specified by:
addScriptProviderListener
in interfaceUtilities
-
removeScriptProviderListener
- Specified by:
removeScriptProviderListener
in interfaceUtilities
-
lookupTag
-
getDistributedDatabases
- Specified by:
getDistributedDatabases
in interfaceUtilities
-
getDistributedDatabases
public List<DistributedDatabase> getDistributedDatabases(String[] networks, Map<String, Object> options) - Specified by:
getDistributedDatabases
in interfaceUtilities
-
registerJSONRPCServer
- Specified by:
registerJSONRPCServer
in interfaceUtilities
-
unregisterJSONRPCServer
- Specified by:
unregisterJSONRPCServer
in interfaceUtilities
-
registerJSONRPCClient
- Specified by:
registerJSONRPCClient
in interfaceUtilities
-
unregisterJSONRPCClient
- Specified by:
unregisterJSONRPCClient
in interfaceUtilities
-
getTagManager
- Specified by:
getTagManager
in interfaceUtilities
-