org.carrot2.input.googleapi
Class GoogleKeysPool

java.lang.Object
  extended by org.carrot2.input.googleapi.GoogleKeysPool

public class GoogleKeysPool
extends Object

A pool for Google API keys.

Author:
Dawid Weiss

Nested Class Summary
(package private) static class GoogleKeysPool.WaitingKey
           
 
Field Summary
static String POOL_SYSPROPERTY
           
 
Constructor Summary
GoogleKeysPool()
           
 
Method Summary
 void addKey(String key)
          Adds a single key to the pool.
 void addKey(String key, String name)
          Adds a single named key to the pool.
 void addKeys(File dir, String extension)
          Adds all keys from files in the given folder.
 GoogleApiKey borrowKey()
           
static GoogleKeysPool getDefault()
          Returns the default instance of a google keys pool, instantiated from a location given in the system property googleapi.keypool.
 int getKeysTotal()
           
 boolean hasActiveKeys()
           
 void returnKey(GoogleApiKey key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POOL_SYSPROPERTY

public static final String POOL_SYSPROPERTY
See Also:
Constant Field Values
Constructor Detail

GoogleKeysPool

public GoogleKeysPool()
Method Detail

borrowKey

public GoogleApiKey borrowKey()
                       throws Exception
Throws:
Exception

returnKey

public void returnKey(GoogleApiKey key)

hasActiveKeys

public boolean hasActiveKeys()

addKey

public void addKey(String key)
Adds a single key to the pool.

Parameters:
key - The key.

addKey

public void addKey(String key,
                   String name)
Adds a single named key to the pool.

Parameters:
key - The key.

addKeys

public void addKeys(File dir,
                    String extension)
             throws IOException
Adds all keys from files in the given folder. A key file is a plain text file. The key must be the only entry on the first line.

Parameters:
dir - The directory to scan.
extension - File extension. Only files ending with this extension will be considered keys.
Throws:
IOException

getKeysTotal

public int getKeysTotal()

getDefault

public static GoogleKeysPool getDefault()
Returns the default instance of a google keys pool, instantiated from a location given in the system property googleapi.keypool.



Copyright (c) Dawid Weiss, Stanislaw Osinski