Package com.github.ambry.account
Class MySqlAccountService
- java.lang.Object
-
- com.github.ambry.account.MySqlAccountService
-
- All Implemented Interfaces:
com.github.ambry.account.AccountService
,java.io.Closeable
,java.lang.AutoCloseable
public class MySqlAccountService extends java.lang.Object
An implementation ofAccountService
that employs MySql database as its underlying storage.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicReference<com.github.ambry.account.AccountInfoMap>
accountInfoMapRef
protected AccountServiceMetrics
accountServiceMetrics
protected java.util.concurrent.CopyOnWriteArraySet<java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>>>
accountUpdateConsumers
protected java.util.concurrent.locks.ReentrantLock
lock
-
Constructor Summary
Constructors Constructor Description MySqlAccountService(AccountServiceMetrics accountServiceMetrics, com.github.ambry.config.MySqlAccountServiceConfig config, MySqlAccountStoreFactory mySqlAccountStoreFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAccountUpdateConsumer(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
protected void
checkOpen()
Ensures the account service is ready to process requests.void
close()
com.github.ambry.account.Account
getAccountById(short accountId)
com.github.ambry.account.Account
getAccountByName(java.lang.String accountName)
java.util.Collection<com.github.ambry.account.Account>
getAllAccounts()
protected void
notifyAccountUpdateConsumers(com.github.ambry.account.AccountInfoMap newAccountInfoMap, com.github.ambry.account.AccountInfoMap oldAccountInfoMap, boolean isCalledFromListener)
Logs and notifies account updateConsumer
s about any new account changes/creations.boolean
removeAccountUpdateConsumer(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
void
selectInactiveContainersAndMarkInZK(com.github.ambry.server.StatsSnapshot statsSnapshot)
boolean
updateAccounts(java.util.Collection<com.github.ambry.account.Account> accounts)
java.util.Collection<com.github.ambry.account.Container>
updateContainers(java.lang.String accountName, java.util.Collection<com.github.ambry.account.Container> containers)
-
-
-
Field Detail
-
accountInfoMapRef
protected final java.util.concurrent.atomic.AtomicReference<com.github.ambry.account.AccountInfoMap> accountInfoMapRef
-
lock
protected final java.util.concurrent.locks.ReentrantLock lock
-
accountUpdateConsumers
protected final java.util.concurrent.CopyOnWriteArraySet<java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>>> accountUpdateConsumers
-
accountServiceMetrics
protected final AccountServiceMetrics accountServiceMetrics
-
-
Constructor Detail
-
MySqlAccountService
public MySqlAccountService(AccountServiceMetrics accountServiceMetrics, com.github.ambry.config.MySqlAccountServiceConfig config, MySqlAccountStoreFactory mySqlAccountStoreFactory) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getAccountById
public com.github.ambry.account.Account getAccountById(short accountId)
- Specified by:
getAccountById
in interfacecom.github.ambry.account.AccountService
-
getAccountByName
public com.github.ambry.account.Account getAccountByName(java.lang.String accountName)
- Specified by:
getAccountByName
in interfacecom.github.ambry.account.AccountService
-
updateAccounts
public boolean updateAccounts(java.util.Collection<com.github.ambry.account.Account> accounts)
-
getAllAccounts
public java.util.Collection<com.github.ambry.account.Account> getAllAccounts()
- Specified by:
getAllAccounts
in interfacecom.github.ambry.account.AccountService
-
addAccountUpdateConsumer
public boolean addAccountUpdateConsumer(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
- Specified by:
addAccountUpdateConsumer
in interfacecom.github.ambry.account.AccountService
-
removeAccountUpdateConsumer
public boolean removeAccountUpdateConsumer(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
- Specified by:
removeAccountUpdateConsumer
in interfacecom.github.ambry.account.AccountService
-
selectInactiveContainersAndMarkInZK
public void selectInactiveContainersAndMarkInZK(com.github.ambry.server.StatsSnapshot statsSnapshot)
-
close
public void close() throws java.io.IOException
- Throws:
java.io.IOException
-
checkOpen
protected void checkOpen()
Ensures the account service is ready to process requests. Throws an unchecked exception (for exampleIllegalStateException
) if the account service is not ready to process requests.
-
updateContainers
public java.util.Collection<com.github.ambry.account.Container> updateContainers(java.lang.String accountName, java.util.Collection<com.github.ambry.account.Container> containers) throws com.github.ambry.account.AccountServiceException
- Specified by:
updateContainers
in interfacecom.github.ambry.account.AccountService
- Throws:
com.github.ambry.account.AccountServiceException
-
notifyAccountUpdateConsumers
protected void notifyAccountUpdateConsumers(com.github.ambry.account.AccountInfoMap newAccountInfoMap, com.github.ambry.account.AccountInfoMap oldAccountInfoMap, boolean isCalledFromListener)
Logs and notifies account updateConsumer
s about any new account changes/creations.- Parameters:
newAccountInfoMap
- the newAccountInfoMap
that has been set.oldAccountInfoMap
- theAccountInfoMap
that was cached before this change.isCalledFromListener
-true
if the caller is the account update listener, {@@code false} otherwise.
-
-