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 classstatic classstatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic interfacestatic interfaceprivate static classNested classes/interfaces inherited from interface Utilities
Utilities.JSONClient, Utilities.JSONServer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Coreprivate static AEThread2private static Listprivate static AESemaphoreprivate static Map<String, Utilities.JSONClient> private static Map<String, Utilities.JSONServer> private static InetAddressprivate static longprivate static WeakHashMap<RateLimiter, UtilitiesImpl.PluginLimitedRateGroup> private static CopyOnWriteList<LocationProvider> private static CopyOnWriteList<LocationProviderListener> private PluginInterfaceprivate static CopyOnWriteList<ScriptProvider> private static List<UtilitiesImpl.searchManager> private static CopyOnWriteList<ScriptProvider.ScriptProviderListener> private UtilitiesImpl.TagManagerImplprivate static ThreadLocal<PluginInterface> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DelayedTaskaddDelayedTask(String name, Runnable r) voidaddLocationProvider(LocationProvider provider) voidvoidvoidstatic voidallocateDirectByteBuffer(int size) allocatePooledByteBuffer(byte[] data) allocatePooledByteBuffer(int length) static <T extends Exception>
voidstatic <T> Tstatic <T, S extends Exception>
TcallWithPluginThreadContext(PluginInterface pi, UtilitiesImpl.runnableWithReturnAndException<T, S> target) static voidcallWithPluginThreadContext(PluginInterface pi, Runnable target) intcompareVersions(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.voidcreateProcess(File working_dirctory, String[] command, String[] env) voidcreateProcess(String command_line) create a child process and executes the supplied command line.voidcreateThread(String name, Runnable target) create and run a thread for the target.createTimer(String name) Creates aUTTimerinstance.createTimer(String name, boolean lightweight) Creates aUTTimerinstance.createTimer(String name, int priority) Creates aUTTimerinstance.createTimer(String name, int max_threads, int priority) createWrapper(byte[] data) voiddeleteResilientBEncodedFile(File parent_dir, String file_name, boolean use_backup) voidfreeDirectByteBuffer(ByteBuffer buffer) longGet 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 PluginInterfaceReturns 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) booleanbooleanbooleanisLinux()booleanisOSX()booleanbooleanisUnix()booleannormaliseFileName(String f_name) Converts a file name so that all characters in the file name are compatible with the underlying filesystem.private static voidqueueTask(UtilitiesImpl.DelayedTaskImpl task, int pos) readResilientBEncodedFile(File parent_dir, String file_name, boolean use_backup) voidvoidvoidregisterScriptProvider(ScriptProvider provider) voidregisterSearchProvider(SearchProvider provider) voidremoveLocationProvider(LocationProvider provider) voidvoidvoidreverseDNSLookup(InetAddress address) attempts a reverse DNS lookup of an address, null if it failsstatic <T> TrunAtLowPriority(String name, Supplier<T> r) booleansupportsPowerStateControl(int state) voidvoidvoidunregisterScriptProvider(ScriptProvider provider) voidunregisterSearchProvider(SearchProvider provider) static RateLimiterwrapLimiter(RateLimiter limiter, boolean disable_disable) voidwriteResilientBEncodedFile(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:
getUserDirin interfaceUtilities
-
getProgramDir
- Specified by:
getProgramDirin interfaceUtilities
-
isWindows
-
isLinux
-
isUnix
-
isFreeBSD
-
isSolaris
-
isOSX
-
isCVSVersion
public boolean isCVSVersion()- Specified by:
isCVSVersionin interfaceUtilities
-
getImageAsStream
- Specified by:
getImageAsStreamin interfaceUtilities
-
getSemaphore
- Specified by:
getSemaphorein interfaceUtilities
-
getMonitor
- Specified by:
getMonitorin interfaceUtilities
-
allocateDirectByteBuffer
- Specified by:
allocateDirectByteBufferin interfaceUtilities
-
freeDirectByteBuffer
- Specified by:
freeDirectByteBufferin interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBufferin interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBufferin interfaceUtilities
-
allocatePooledByteBuffer
- Specified by:
allocatePooledByteBufferin interfaceUtilities- Parameters:
map- must be b-encodable- Returns:
- Throws:
IOException
-
getFormatters
- Specified by:
getFormattersin interfaceUtilities
-
getLocaleUtilities
- Specified by:
getLocaleUtilitiesin interfaceUtilities
-
createTimer
Description copied from interface:UtilitiesCreates aUTTimerinstance. It will be configured for non-lightweight tasks by default.- Specified by:
createTimerin interfaceUtilities- Parameters:
name- Name for the UTTimer object.- Returns:
- A UTTimer instance.
-
createTimer
Description copied from interface:UtilitiesCreates aUTTimerinstance.- Specified by:
createTimerin 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:UtilitiesCreates aUTTimerinstance.- Specified by:
createTimerin interfaceUtilities- Parameters:
name- Name for the UTTimer object.priority- The Thread.XXX_PRIORITY value to use.- Returns:
- A UTTimer instance.
-
createTimer
- Specified by:
createTimerin interfaceUtilities
-
createThread
Description copied from interface:Utilitiescreate 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:
createThreadin interfaceUtilities- Parameters:
name-target-
-
createProcess
Description copied from interface:Utilitiescreate 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:
createProcessin interfaceUtilities- Parameters:
command_line-- Throws:
PluginException
-
createProcess
public void createProcess(File working_dirctory, String[] command, String[] env) throws PluginException - Specified by:
createProcessin interfaceUtilities- Throws:
PluginException
-
getResourceDownloaderFactory
- Specified by:
getResourceDownloaderFactoryin interfaceUtilities
-
getResourceUploaderFactory
- Specified by:
getResourceUploaderFactoryin interfaceUtilities
-
getSecurityManager
- Specified by:
getSecurityManagerin interfaceUtilities
-
getSimpleXMLParserDocumentFactory
- Specified by:
getSimpleXMLParserDocumentFactoryin interfaceUtilities
-
getRSSFeed
- Specified by:
getRSSFeedin interfaceUtilities- Throws:
SimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(URL feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException - Specified by:
getRSSFeedin interfaceUtilities- Throws:
ResourceDownloaderExceptionSimpleXMLParserDocumentException
-
getRSSFeed
public RSSFeed getRSSFeed(URL source_url, ResourceDownloader feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException - Specified by:
getRSSFeedin interfaceUtilities- Throws:
ResourceDownloaderExceptionSimpleXMLParserDocumentException
-
getPublicAddress
- Specified by:
getPublicAddressin interfaceUtilities
-
getPublicAddress
Description copied from interface:UtilitiesReturns a public IP address of the machine or null if it can't be determined- Specified by:
getPublicAddressin interfaceUtilities
-
reverseDNSLookup
Description copied from interface:Utilitiesattempts a reverse DNS lookup of an address, null if it fails- Specified by:
reverseDNSLookupin interfaceUtilities- Parameters:
address-- Returns:
-
getCurrentSystemTime
public long getCurrentSystemTime()Description copied from interface:UtilitiesGet the current system time, like System.currentTimeMillis(), only the time lookup is cached for performance reasons.- Specified by:
getCurrentSystemTimein interfaceUtilities- Returns:
- current system time
-
createWrapper
- Specified by:
createWrapperin interfaceUtilities
-
createAggregatedDispatcher
public AggregatedDispatcher createAggregatedDispatcher(long idle_dispatch_time, long max_queue_size) Description copied from interface:Utilitiescreate 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:
createAggregatedDispatcherin 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:
createAggregatedListin 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:
readResilientBEncodedFilein 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:
writeResilientBEncodedFilein interfaceUtilities
-
deleteResilientBEncodedFile
- Specified by:
deleteResilientBEncodedFilein interfaceUtilities
-
compareVersions
Description copied from interface:UtilitiesCompares 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:
compareVersionsin 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:UtilitiesConverts 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:
normaliseFileNamein interfaceUtilities- Parameters:
f_name- File name to convert.- Returns:
- Converted file name.
-
createDelayedTask
Description copied from interface:UtilitiesAdds 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:
createDelayedTaskin interfaceUtilities- Returns:
-
runAtLowPriority
-
addDelayedTask
-
queueTask
-
registerSearchProvider
- Specified by:
registerSearchProviderin interfaceUtilities- Throws:
SearchException
-
unregisterSearchProvider
- Specified by:
unregisterSearchProviderin interfaceUtilities- Throws:
SearchException
-
getSearchInitiator
- Specified by:
getSearchInitiatorin interfaceUtilities- Throws:
SearchException
-
addSearchManager
-
getSubscriptionManager
- Specified by:
getSubscriptionManagerin interfaceUtilities- Throws:
SubscriptionException
-
supportsPowerStateControl
public boolean supportsPowerStateControl(int state) - Specified by:
supportsPowerStateControlin interfaceUtilities
-
addPowerManagementListener
- Specified by:
addPowerManagementListenerin interfaceUtilities
-
removePowerManagementListener
- Specified by:
removePowerManagementListenerin interfaceUtilities
-
getLocationProviders
- Specified by:
getLocationProvidersin interfaceUtilities
-
addLocationProvider
- Specified by:
addLocationProviderin interfaceUtilities
-
removeLocationProvider
- Specified by:
removeLocationProviderin interfaceUtilities
-
addLocationProviderListener
- Specified by:
addLocationProviderListenerin interfaceUtilities
-
removeLocationProviderListener
- Specified by:
removeLocationProviderListenerin interfaceUtilities
-
getScriptProviders
- Specified by:
getScriptProvidersin interfaceUtilities
-
registerScriptProvider
- Specified by:
registerScriptProviderin interfaceUtilities
-
unregisterScriptProvider
- Specified by:
unregisterScriptProviderin interfaceUtilities
-
addScriptProviderListener
- Specified by:
addScriptProviderListenerin interfaceUtilities
-
removeScriptProviderListener
- Specified by:
removeScriptProviderListenerin interfaceUtilities
-
lookupTag
-
getDistributedDatabases
- Specified by:
getDistributedDatabasesin interfaceUtilities
-
getDistributedDatabases
public List<DistributedDatabase> getDistributedDatabases(String[] networks, Map<String, Object> options) - Specified by:
getDistributedDatabasesin interfaceUtilities
-
registerJSONRPCServer
- Specified by:
registerJSONRPCServerin interfaceUtilities
-
unregisterJSONRPCServer
- Specified by:
unregisterJSONRPCServerin interfaceUtilities
-
registerJSONRPCClient
- Specified by:
registerJSONRPCClientin interfaceUtilities
-
unregisterJSONRPCClient
- Specified by:
unregisterJSONRPCClientin interfaceUtilities
-
getTagManager
- Specified by:
getTagManagerin interfaceUtilities
-