-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#780] Implement TenantClientFactoryImpl.
The methods for creating TenantClient instances have been moved from HonoConnectionImpl to TenantClientFactoryImpl. Signed-off-by: Kai Hudalla <[email protected]>
- Loading branch information
Kai Hudalla
committed
Apr 15, 2019
1 parent
cf56777
commit e8722f2
Showing
7 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
client/src/main/java/org/eclipse/hono/client/impl/TenantClientFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Copyright (c) 2019 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
|
||
package org.eclipse.hono.client.impl; | ||
|
||
import org.eclipse.hono.cache.CacheProvider; | ||
import org.eclipse.hono.client.HonoConnection; | ||
import org.eclipse.hono.client.TenantClient; | ||
import org.eclipse.hono.client.TenantClientFactory; | ||
|
||
import io.vertx.core.Future; | ||
|
||
|
||
/** | ||
* A factory for creating clients for Hono's Tenant service. | ||
* | ||
*/ | ||
public class TenantClientFactoryImpl extends AbstractHonoClientFactory implements TenantClientFactory { | ||
|
||
private final CachingClientFactory<TenantClient> tenantClientFactory; | ||
private final CacheProvider cacheProvider; | ||
|
||
/** | ||
* Creates a new factory for an existing connection. | ||
* | ||
* @param connection The connection to use. | ||
* @param cacheProvider The cache provider to use for creating caches for tenant objects | ||
* or {@code null} if tenant objects should not be cached. | ||
* @throws NullPointerException if connection is {@code null} | ||
*/ | ||
public TenantClientFactoryImpl(final HonoConnection connection, final CacheProvider cacheProvider) { | ||
super(connection); | ||
this.tenantClientFactory = new CachingClientFactory<>(c -> c.isOpen()); | ||
this.cacheProvider = cacheProvider; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void onDisconnect() { | ||
tenantClientFactory.clearState(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Future<TenantClient> getOrCreateTenantClient() { | ||
|
||
return connection.executeOrRunOnContext(result -> { | ||
tenantClientFactory.getOrCreateClient( | ||
TenantClientImpl.getTargetAddress(), | ||
() -> TenantClientImpl.create( | ||
cacheProvider, | ||
connection, | ||
this::removeTenantClient, | ||
this::removeTenantClient), | ||
result); | ||
}); | ||
} | ||
|
||
private void removeTenantClient(final String tenantId) { | ||
// the tenantId is not relevant for this client, so ignore it | ||
tenantClientFactory.removeClient(TenantClientImpl.getTargetAddress()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters