本文整理汇总了Java中com.mysql.fabric.FabricCommunicationException类的典型用法代码示例。如果您正苦于以下问题:Java FabricCommunicationException类的具体用法?Java FabricCommunicationException怎么用?Java FabricCommunicationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FabricCommunicationException类属于com.mysql.fabric包,在下文中一共展示了FabricCommunicationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public List<?> call(String methodName, Object args[]) throws FabricCommunicationException {
String authenticateHeader;
try {
authenticateHeader = DigestAuthentication.getChallengeHeader(this.url);
} catch (IOException ex) {
throw new FabricCommunicationException("Unable to obtain challenge header for authentication", ex);
}
Map<String, String> digestChallenge = DigestAuthentication.parseDigestChallenge(authenticateHeader);
String authorizationHeader = DigestAuthentication.generateAuthorizationHeader(digestChallenge, this.username, this.password);
this.underlyingCaller.setHeader("Authorization", authorizationHeader);
return this.underlyingCaller.call(methodName, args);
}
示例2: getServerGroups
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Facade for "dump.servers". Will not return empty server groups.
*/
public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern) throws FabricCommunicationException {
int version = 0; // necessary but unused
Response response = errorSafeCallMethod(METHOD_DUMP_SERVERS, new Object[] { version, groupPattern });
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (Map<String, ?> server : response.getResultSet()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
}
serversByGroupName.get(s.getGroupName()).add(s);
}
// create group set
Set<ServerGroup> serverGroups = new HashSet<ServerGroup>();
for (Map.Entry<String, Set<Server>> entry : serversByGroupName.entrySet()) {
ServerGroup g = new ServerGroup(entry.getKey(), entry.getValue());
serverGroups.add(g);
}
return new FabricStateResponse<Set<ServerGroup>>(serverGroups, response.getTtl());
}
示例3: getShardIndices
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
private FabricStateResponse<Set<ShardIndex>> getShardIndices(int shardMappingId) throws FabricCommunicationException {
int version = 0;
Object args[] = new Object[] { version, String.valueOf(shardMappingId) };
Response indexResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_INDEX, args);
Set<ShardIndex> indices = new HashSet<ShardIndex>();
// construct the index
for (Map<String, ?> rawIndexEntry : indexResponse.getResultSet()) {
String bound = (String) rawIndexEntry.get(FIELD_LOWER_BOUND);
int shardId = (Integer) rawIndexEntry.get(FIELD_SHARD_ID);
String groupName = (String) rawIndexEntry.get(FIELD_GROUP_ID);
ShardIndex si = new ShardIndex(bound, shardId, groupName);
indices.add(si);
}
return new FabricStateResponse<Set<ShardIndex>>(indices, indexResponse.getTtl());
}
示例4: addQueryTable
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Add a table to the set of tables used for the next query on this connection.
* This is used for:
* <ul>
* <li>Choosing a shard given the tables used</li>
* <li>Preventing cross-shard queries</li>
* </ul>
*/
public void addQueryTable(String tableName) throws SQLException {
ensureNoTransactionInProgress();
this.currentConnection = null;
try {
// choose shard mapping if necessary
if (this.shardMapping == null) {
if (this.fabricConnection.getShardMapping(this.database, tableName) != null) {
setShardTable(tableName);
}
} else { // make sure we aren't in conflict with the chosen shard mapping
ShardMapping mappingForTableName = this.fabricConnection.getShardMapping(this.database, tableName);
if (mappingForTableName != null && !mappingForTableName.equals(this.shardMapping)) {
throw SQLError.createSQLException("Cross-shard query not allowed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, null, getExceptionInterceptor(),
this);
}
}
this.queryTables.add(tableName);
} catch (FabricCommunicationException ex) {
throw SQLError.createSQLException("Fabric communication failure.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, getExceptionInterceptor(),
this);
}
}
示例5: getServerGroups
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Facade for "dump.servers". Will not return empty server groups.
*/
public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern) throws FabricCommunicationException {
int version = 0; // necessary but unused
Response response = errorSafeCallMethod(METHOD_DUMP_SERVERS, new Object[] { version, groupPattern });
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (Map server : response.getResultSet()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
}
serversByGroupName.get(s.getGroupName()).add(s);
}
// create group set
Set<ServerGroup> serverGroups = new HashSet<ServerGroup>();
for (Map.Entry<String, Set<Server>> entry : serversByGroupName.entrySet()) {
ServerGroup g = new ServerGroup(entry.getKey(), entry.getValue());
serverGroups.add(g);
}
return new FabricStateResponse<Set<ServerGroup>>(serverGroups, response.getTtl());
}
示例6: getShardIndices
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
private FabricStateResponse<Set<ShardIndex>> getShardIndices(int shardMappingId) throws FabricCommunicationException {
int version = 0;
Object args[] = new Object[] { version, String.valueOf(shardMappingId) };
Response indexResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_INDEX, args);
Set<ShardIndex> indices = new HashSet<ShardIndex>();
// construct the index
for (Map rawIndexEntry : indexResponse.getResultSet()) {
String bound = (String) rawIndexEntry.get(FIELD_LOWER_BOUND);
int shardId = (Integer) rawIndexEntry.get(FIELD_SHARD_ID);
String groupName = (String) rawIndexEntry.get(FIELD_GROUP_ID);
ShardIndex si = new ShardIndex(bound, shardId, groupName);
indices.add(si);
}
return new FabricStateResponse<Set<ShardIndex>>(indices, indexResponse.getTtl());
}
示例7: testCreateGroup
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public void testCreateGroup() throws Exception {
if (!this.isSetForFabricTest) {
return;
}
String testGroupName = "CJ-testGroupName";
try {
this.client.destroyGroup(testGroupName);
} catch (FabricCommunicationException ex) {
}
this.client.createGroup(testGroupName);
// will throw an exception if the group wasn't created
this.client.destroyGroup(testGroupName);
}
示例8: interceptException
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public SQLException interceptException(SQLException sqlEx, Connection conn) {
MySQLConnection mysqlConn = (MySQLConnection) conn;
// don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
return null;
}
FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
try {
return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
} catch (FabricCommunicationException ex) {
return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
}
}
示例9: FabricMultiTenantConnectionProvider
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public FabricMultiTenantConnectionProvider(String fabricUrl, String database, String table, String user, String password, String fabricUser,
String fabricPassword) {
try {
this.fabricConnection = new FabricConnection(fabricUrl, fabricUser, fabricPassword);
this.database = database;
this.table = table;
this.user = user;
this.password = password;
this.shardMapping = this.fabricConnection.getShardMapping(this.database, this.table);
this.globalGroup = this.fabricConnection.getServerGroup(this.shardMapping.getGlobalGroupName());
} catch (FabricCommunicationException ex) {
throw new RuntimeException(ex);
}
}
示例10: getShardTables
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
private FabricStateResponse<Set<ShardTable>> getShardTables(int shardMappingId) throws FabricCommunicationException {
int version = 0;
Object args[] = new Object[] { version, String.valueOf(shardMappingId) };
Response tablesResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_TABLES, args);
Set<ShardTable> tables = new HashSet<ShardTable>();
// construct the tables
for (Map<String, ?> rawTable : tablesResponse.getResultSet()) {
String database = (String) rawTable.get(FIELD_SCHEMA_NAME);
String table = (String) rawTable.get(FIELD_TABLE_NAME);
String column = (String) rawTable.get(FIELD_COLUMN_NAME);
ShardTable st = new ShardTable(database, table, column);
tables.add(st);
}
return new FabricStateResponse<Set<ShardTable>>(tables, tablesResponse.getTtl());
}
示例11: toServerSet
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Convert a list of string/string/bool to Server objects.
*/
private static Set<Server> toServerSet(List<Map<String, ?>> l) throws FabricCommunicationException {
Set<Server> servers = new HashSet<Server>();
for (Map<String, ?> serverData : l) {
servers.add(unmarshallServer(serverData));
}
return servers;
}
示例12: getGroupNames
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Return a list of groups present in this fabric.
*/
public Set<String> getGroupNames() throws FabricCommunicationException {
Set<String> groupNames = new HashSet<String>();
for (Map<String, ?> row : errorSafeCallMethod(METHOD_GROUP_LOOKUP_GROUPS, null).getResultSet()) {
groupNames.add((String) row.get(FIELD_GROUP_ID));
}
return groupNames;
}
示例13: getServerGroup
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public ServerGroup getServerGroup(String groupName) throws FabricCommunicationException {
Set<ServerGroup> groups = getServerGroups(groupName).getData();
if (groups.size() == 1) {
return groups.iterator().next();
}
return null;
}
示例14: getShardMappings
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
/**
* Retrieve a set of complete shard mappings. The returned mappings include all information
* available about the mapping.
*
* @param shardMappingIdPattern
* the shard mapping id to retrieve
*/
public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappingIdPattern) throws FabricCommunicationException {
int version = 0;
Object args[] = new Object[] { version, shardMappingIdPattern }; // common to all calls
Response mapsResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_MAPS, args);
// use the lowest ttl of all the calls
long minExpireTimeMillis = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(mapsResponse.getTtl());
int baseTtl = mapsResponse.getTtl();
// construct the maps
Set<ShardMapping> mappings = new HashSet<ShardMapping>();
for (Map<String, ?> rawMapping : mapsResponse.getResultSet()) {
int mappingId = (Integer) rawMapping.get(FIELD_MAPPING_ID);
ShardingType shardingType = ShardingType.valueOf((String) rawMapping.get(FIELD_TYPE_NAME));
String globalGroupName = (String) rawMapping.get(FIELD_GLOBAL_GROUP_ID);
FabricStateResponse<Set<ShardTable>> tables = getShardTables(mappingId);
FabricStateResponse<Set<ShardIndex>> indices = getShardIndices(mappingId);
if (tables.getExpireTimeMillis() < minExpireTimeMillis) {
minExpireTimeMillis = tables.getExpireTimeMillis();
}
if (indices.getExpireTimeMillis() < minExpireTimeMillis) {
minExpireTimeMillis = indices.getExpireTimeMillis();
}
ShardMapping m = new ShardMappingFactory().createShardMapping(mappingId, shardingType, globalGroupName, tables.getData(), indices.getData());
mappings.add(m);
}
return new FabricStateResponse<Set<ShardMapping>>(mappings, baseTtl, minExpireTimeMillis);
}
示例15: reportServerError
import com.mysql.fabric.FabricCommunicationException; //导入依赖的package包/类
public void reportServerError(Server server, String errorDescription, boolean forceFaulty) throws FabricCommunicationException {
String reporter = THREAT_REPORTER_NAME;
String command = METHOD_THREAT_REPORT_ERROR;
if (forceFaulty) {
command = METHOD_THREAT_REPORT_FAILURE;
}
errorSafeCallMethod(command, new Object[] { server.getUuid(), reporter, errorDescription });
}