List of usage examples for java.util Map equals
boolean equals(Object o);
From source file:org.apache.eagle.alert.metadata.impl.JdbcImplTest.java
@Test public void testUpdate() throws SQLException { OpResult updateResult;/* w w w . j a v a 2 s .c o m*/ // update Publishment publishment = new Publishment(); publishment.setName("pub-"); publishment.setType("type1"); updateResult = dao.addPublishment(publishment); Assert.assertTrue(updateResult.code == OpResult.SUCCESS); publishment.setType("type2"); updateResult = dao.addPublishment(publishment); Assert.assertTrue(updateResult.code == OpResult.SUCCESS); Assert.assertTrue(dao.listPublishment().get(0).getType().equals("type2")); // remove updateResult = dao.removePublishment("pub-"); Assert.assertTrue(updateResult.code == OpResult.SUCCESS); Assert.assertTrue(dao.listPublishment().size() == 0); // update alert event AlertPublishEvent alert = new AlertPublishEvent(); String alertId = UUID.randomUUID().toString(); alert.setAlertTimestamp(System.currentTimeMillis()); alert.setAlertId(alertId); alert.setPolicyId("policyId"); alert.setPolicyValue( "from HDFS_AUDIT_LOG_ENRICHED_STREAM_SANDBOX[str:contains(src,'/tmp/test') and ((cmd=='rename' and str:contains(dst, '.Trash')) or cmd=='delete')] select * insert into hdfs_audit_log_enriched_stream_out"); Map<String, Object> alertData = new HashMap<>(); alertData.put("siteId", "sandbox"); alertData.put("policyId", "sample"); alert.setAlertData(alertData); List<String> appIds = new ArrayList<>(); appIds.add("app1"); appIds.add("app2"); alert.setAppIds(appIds); updateResult = dao.addAlertPublishEvent(alert); Assert.assertTrue(updateResult.code == OpResult.SUCCESS); AlertPublishEvent event = dao.getAlertPublishEvent(alertId); Assert.assertTrue(CollectionUtils.isEqualCollection(appIds, event.getAppIds())); Assert.assertTrue(alertData.equals(event.getAlertData())); }
From source file:org.deri.iris.queryrewriting.PositionDependenciesTest.java
@Test public void testPositionDependenciesLinearCyclic() throws Exception { //// w w w . j av a 2 s . c o m // Theory: // // [R1] t(X,Y) -> s(X). // [R2] t(X,Y) -> t(Y,X). // final IPredicate t = Factory.BASIC.createPredicate("t", 2); final IPredicate s = Factory.BASIC.createPredicate("s", 1); final ILiteral txy = Factory.BASIC.createLiteral(true, t, tupleXY); final ILiteral tyx = Factory.BASIC.createLiteral(true, t, tupleYX); final ILiteral sx = Factory.BASIC.createLiteral(true, s, tupleX); // Input structure final List<ILiteral> h1 = new LinkedList<ILiteral>(); final List<ILiteral> b1 = new LinkedList<ILiteral>(); b1.add(txy); h1.add(sx); final List<ILiteral> h2 = new LinkedList<ILiteral>(); final List<ILiteral> b2 = new LinkedList<ILiteral>(); b2.add(txy); h2.add(tyx); final IRule r1 = Factory.BASIC.createRule(h1, b1); final IRule r2 = Factory.BASIC.createRule(h2, b2); final List<IRule> in = ImmutableList.of(r1, r2); // // Comparison Structure: // // t[1] -> t[1] {<>, <R2,R2>} // t[2] -> t[2] {<>, <R2,R2>} // s[1] -> s[1] {<>} // // t[1] -> s[1] {<R1>} // t[1] -> t[2] {<R2>} // t[2] -> t[1] {<R2>} // // t[2] -> s[1] {<R2,R1>} // final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> cmp = new HashMap<Pair<IPosition, IPosition>, Set<List<IRule>>>(); final IPosition t1 = new Position(t.getPredicateSymbol(), 1); final IPosition t2 = new Position(t.getPredicateSymbol(), 2); final IPosition s1 = new Position(s.getPredicateSymbol(), 1); final List<IRule> lEmpty = ImmutableList.of(); final List<IRule> lr2r2 = ImmutableList.of(r2, r2); final Set<List<IRule>> st1t1 = Sets.newHashSet(); st1t1.add(lEmpty); st1t1.add(lr2r2); final Set<List<IRule>> st2t2 = Sets.newHashSet(); st2t2.add(lEmpty); st2t2.add(lr2r2); final Set<List<IRule>> ss1s1 = Sets.newHashSet(); ss1s1.add(lEmpty); // t[1] -> t[1] {<>, <R2,R2>} cmp.put(Pair.of(t1, t1), st1t1); // t[2] -> t[2] {<>, <R2,R2>} cmp.put(Pair.of(t2, t2), st2t2); // s[1] -> s[1] {<>} cmp.put(Pair.of(s1, s1), ss1s1); // t[1] -> s[1] {<R1>} final List<IRule> lr1 = ImmutableList.of(r1); final Set<List<IRule>> slr1 = Sets.newHashSet(); slr1.add(lr1); cmp.put(Pair.of(t1, s1), slr1); // t[2] -> s[1] {<R2,R1>} final List<IRule> lr2r1 = ImmutableList.of(r2, r1); final Set<List<IRule>> slr2r1 = Sets.newHashSet(); slr2r1.add(lr2r1); cmp.put(Pair.of(t2, s1), slr2r1); // t[1] -> t[2] {<R2>} // t[2] -> t[1] {<R2>} final List<IRule> lr2 = ImmutableList.of(r2); final Set<List<IRule>> slr2 = Sets.newHashSet(); slr2.add(lr2); cmp.put(Pair.of(t1, t2), slr2); cmp.put(Pair.of(t2, t1), slr2); final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> depGraph = DepGraphUtils .computePositionDependencyGraph(in); LOGGER.debug(depGraph.toString()); System.out.println("Actual:" + depGraph.toString()); System.out.println("Expected:" + cmp.toString()); assertEquals(true, depGraph.equals(cmp)); }
From source file:org.deri.iris.queryrewriting.PositionDependenciesTest.java
@Test public void testPositionDependenciesLinearCyclicMultiWay() throws Exception { //// ww w . j a v a 2 s . co m // Theory: // // [R1] p(X) -> t(X,Y). // [R2] t(X,Y) -> s(X). // [R3] t(X,Y) -> t(Y,X). // [R4] t(X,Y) -> s(Y). // final IPredicate p = Factory.BASIC.createPredicate("p", 1); final IPredicate t = Factory.BASIC.createPredicate("t", 2); final IPredicate s = Factory.BASIC.createPredicate("s", 1); final ILiteral px = Factory.BASIC.createLiteral(true, p, tupleX); final ILiteral txy = Factory.BASIC.createLiteral(true, t, tupleXY); final ILiteral tyx = Factory.BASIC.createLiteral(true, t, tupleYX); final ILiteral sx = Factory.BASIC.createLiteral(true, s, tupleX); final ILiteral sy = Factory.BASIC.createLiteral(true, s, tupleY); // Input structure final List<ILiteral> h1 = new LinkedList<ILiteral>(); final List<ILiteral> b1 = new LinkedList<ILiteral>(); b1.add(px); h1.add(txy); final List<ILiteral> h2 = new LinkedList<ILiteral>(); final List<ILiteral> b2 = new LinkedList<ILiteral>(); b2.add(txy); h2.add(sx); final List<ILiteral> h3 = new LinkedList<ILiteral>(); final List<ILiteral> b3 = new LinkedList<ILiteral>(); b3.add(txy); h3.add(tyx); final List<ILiteral> h4 = new LinkedList<ILiteral>(); final List<ILiteral> b4 = new LinkedList<ILiteral>(); b4.add(txy); h4.add(sy); final IRule r1 = Factory.BASIC.createRule(h1, b1); final IRule r2 = Factory.BASIC.createRule(h2, b2); final IRule r3 = Factory.BASIC.createRule(h3, b3); final IRule r4 = Factory.BASIC.createRule(h4, b4); final List<IRule> in = ImmutableList.of(r1, r2, r3, r4); // // Comparison Structure: // // p[1] -> p[1] {<>} // t[1] -> t[1] {<>} // t[2] -> t[2] {<>} // s[1] -> s[1] {<>} // // p[1] -> t[1] {<R1>} // t[1] -> s[1] {<R2>} // p[1] -> m[1] {<R3>} // s[1] -> m[1] {<R4>} // // t[2] -> m[1] {<R2,R4>} // final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> cmp = new HashMap<Pair<IPosition, IPosition>, Set<List<IRule>>>(); final IPosition p1 = new Position(p.getPredicateSymbol(), 1); final IPosition t1 = new Position(t.getPredicateSymbol(), 1); final IPosition t2 = new Position(t.getPredicateSymbol(), 2); final IPosition s1 = new Position(s.getPredicateSymbol(), 1); final List<IRule> lEmpty = ImmutableList.of(); final Set<List<IRule>> slEmpty = Sets.newHashSet(); slEmpty.add(lEmpty); cmp.put(Pair.of(p1, p1), slEmpty); // p[1] -> p[1] {<>} cmp.put(Pair.of(t1, t1), slEmpty); // t[1] -> t[1] {<>} cmp.put(Pair.of(t2, t2), slEmpty); // t[2] -> t[2] {<>} cmp.put(Pair.of(s1, s1), slEmpty); // s[1] -> s[1] {<>} // p[1] -> t[1] {<R1>} final List<IRule> lr1 = ImmutableList.of(r1); final Set<List<IRule>> slr1 = Sets.newHashSet(); slr1.add(lr1); cmp.put(Pair.of(p1, t1), slr1); // t[1] -> s[1] {<R2>} final List<IRule> lr2 = ImmutableList.of(r2); final Set<List<IRule>> slr2 = Sets.newHashSet(); slr1.add(lr2); cmp.put(Pair.of(t1, s1), slr2); // t[1] -> t[2] {<R3>} // t[2] -> t[1] {<R3>} final List<IRule> lr3 = ImmutableList.of(r3); final Set<List<IRule>> slr3 = Sets.newHashSet(); slr3.add(lr3); cmp.put(Pair.of(t1, t2), slr3); cmp.put(Pair.of(t2, t1), slr3); // t[2] -> s[1] {<R4>} final List<IRule> lr4 = ImmutableList.of(r4); final Set<List<IRule>> slr4 = Sets.newHashSet(); slr4.add(lr4); cmp.put(Pair.of(t2, s1), slr4); final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> depGraph = DepGraphUtils .computePositionDependencyGraph(in); LOGGER.debug(depGraph.toString()); System.out.println("Actual:" + depGraph.toString()); System.out.println("Expected:" + cmp.toString()); assertEquals(true, depGraph.equals(cmp)); }
From source file:org.deri.iris.queryrewriting.PositionDependenciesTest.java
@Test public void testPositionDependenciesLinearAcyclicSingleWay() throws Exception { ///*from w w w .ja v a 2 s. c om*/ // Theory: // // [R1] p(X) -> t(X,Y). // [R2] t(X,Y) -> s(Y). // [R3] p(X) -> m(X). // [R4] s(X) -> m(X). // final IPredicate p = Factory.BASIC.createPredicate("p", 1); final IPredicate t = Factory.BASIC.createPredicate("t", 2); final IPredicate s = Factory.BASIC.createPredicate("s", 1); final IPredicate m = Factory.BASIC.createPredicate("m", 1); final ILiteral px = Factory.BASIC.createLiteral(true, p, tupleX); final ILiteral txy = Factory.BASIC.createLiteral(true, t, tupleXY); final ILiteral sx = Factory.BASIC.createLiteral(true, s, tupleX); final ILiteral sy = Factory.BASIC.createLiteral(true, s, tupleY); final ILiteral mx = Factory.BASIC.createLiteral(true, m, tupleX); // Input structure final List<ILiteral> h1 = new LinkedList<ILiteral>(); final List<ILiteral> b1 = new LinkedList<ILiteral>(); h1.add(txy); b1.add(px); final List<ILiteral> h2 = new LinkedList<ILiteral>(); final List<ILiteral> b2 = new LinkedList<ILiteral>(); h2.add(sy); b2.add(txy); final List<ILiteral> h3 = new LinkedList<ILiteral>(); final List<ILiteral> b3 = new LinkedList<ILiteral>(); h3.add(mx); b3.add(px); final List<ILiteral> h4 = new LinkedList<ILiteral>(); final List<ILiteral> b4 = new LinkedList<ILiteral>(); h4.add(mx); b4.add(sx); final IRule r1 = Factory.BASIC.createRule(h1, b1); final IRule r2 = Factory.BASIC.createRule(h2, b2); final IRule r3 = Factory.BASIC.createRule(h3, b3); final IRule r4 = Factory.BASIC.createRule(h4, b4); final List<IRule> in = ImmutableList.of(r1, r2, r3, r4); // // Comparison Structure: // // p[1] -> p[1] {<>} // t[1] -> t[1] {<>} // t[2] -> t[2] {<>} // s[1] -> s[1] {<>} // m[1] -> m[1] {<>} // // p[1] -> t[1] {<R1>} // t[2] -> s[1] {<R2>} // p[1] -> m[1] {<R3>} // s[1] -> m[1] {<R4>} // // t[2] -> m[1] {<R2,R4>} // final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> cmp = new HashMap<Pair<IPosition, IPosition>, Set<List<IRule>>>(); final IPosition p1 = new Position(p.getPredicateSymbol(), 1); final IPosition t1 = new Position(t.getPredicateSymbol(), 1); final IPosition t2 = new Position(t.getPredicateSymbol(), 2); final IPosition s1 = new Position(s.getPredicateSymbol(), 1); final IPosition m1 = new Position(m.getPredicateSymbol(), 1); final List<IRule> lEmpty = ImmutableList.of(); final Set<List<IRule>> slEmpty = ImmutableSet.of(lEmpty); cmp.put(Pair.of(p1, p1), slEmpty); // p[1] -> p[1] {<>} cmp.put(Pair.of(t1, t1), slEmpty); // t[1] -> t[1] {<>} cmp.put(Pair.of(t2, t2), slEmpty); // t[2] -> t[2] {<>} cmp.put(Pair.of(s1, s1), slEmpty); // s[1] -> s[1] {<>} cmp.put(Pair.of(m1, m1), slEmpty); // m[1] -> m[1] {<>} final List<IRule> lr1 = ImmutableList.of(r1); // p[1] -> t[1] {<R1>} final Set<List<IRule>> slr1 = Sets.newHashSet(); slr1.add(lr1); cmp.put(Pair.of(p1, t1), slr1); final List<IRule> lr2 = ImmutableList.of(r2); // t[2] -> s[1] {<R2>} final Set<List<IRule>> slr2 = Sets.newHashSet(); slr2.add(lr2); cmp.put(Pair.of(t2, s1), slr2); final List<IRule> lr3 = ImmutableList.of(r3); // p[1] -> m[1] {<R3>} final Set<List<IRule>> slr3 = Sets.newHashSet(); slr3.add(lr3); cmp.put(Pair.of(p1, m1), slr3); final List<IRule> lr4 = ImmutableList.of(r4); // s[1] -> m[1] {<R4>} final Set<List<IRule>> slr4 = Sets.newHashSet(); slr4.add(lr4); cmp.put(Pair.of(s1, m1), slr4); final List<IRule> lr2r4 = ImmutableList.of(r2, r4); // t[2] -> m[1] {<R2,R4>} final Set<List<IRule>> slr2r4 = Sets.newHashSet(); slr2r4.add(lr2r4); cmp.put(Pair.of(t2, m1), slr2r4); final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> depGraph = DepGraphUtils .computePositionDependencyGraph(in); System.out.println("Actual:" + depGraph.toString()); System.out.println("Expected:" + cmp.toString()); LOGGER.debug(depGraph.toString()); assertEquals(true, depGraph.equals(cmp)); }
From source file:org.killbill.billing.plugin.util.http.HttpClient.java
protected AsyncHttpClient.BoundRequestBuilder getBuilderWithHeaderAndQuery(final String verb, final String url, final Map<String, String> immutableOptions) { final AsyncHttpClient.BoundRequestBuilder builder; if (GET.equals(verb)) { builder = httpClient.prepareGet(url); } else if (POST.equals(verb)) { builder = httpClient.preparePost(url); } else if (PUT.equals(verb)) { builder = httpClient.preparePut(url); } else if (DELETE.equals(verb)) { builder = httpClient.prepareDelete(url); } else if (HEAD.equals(verb)) { builder = httpClient.prepareHead(url); } else if (OPTIONS.equals(verb)) { builder = httpClient.prepareOptions(url); } else {/* ww w . j a v a 2 s .c om*/ throw new IllegalArgumentException("Unrecognized verb: " + verb); } if (username != null || password != null) { final Realm.RealmBuilder realm = new Realm.RealmBuilder(); if (username != null) { realm.setPrincipal(username); } if (password != null) { realm.setPassword(password); } // Unclear why it's now needed realm.setUsePreemptiveAuth(true); realm.setScheme(Realm.AuthScheme.BASIC); builder.setRealm(realm.build()); } final Map<String, String> options = new HashMap<String, String>(immutableOptions); if (options.get(HttpHeaders.ACCEPT) != null) { builder.addHeader(HttpHeaders.ACCEPT, options.remove(HttpHeaders.ACCEPT)); } if (options.get(HttpHeaders.CONTENT_TYPE) != null) { builder.addHeader(HttpHeaders.CONTENT_TYPE, options.remove(HttpHeaders.CONTENT_TYPE)); } for (final String key : options.keySet()) { if (options.get(key) != null) { builder.addQueryParam(key, options.get(key)); } } if (proxyHost != null && proxyPort != null) { final ProxyServer proxyServer = new ProxyServer(proxyHost, proxyPort); builder.setProxyServer(proxyServer); } return builder; }
From source file:org.elasticsearch.xpack.watcher.actions.jira.JiraActionTests.java
public void testEquals() throws Exception { final JiraAction action1 = randomJiraAction(); String account = action1.account; Map<String, Object> fields = action1.fields; HttpProxy proxy = action1.proxy;/* w ww . j a v a 2s .c o m*/ boolean equals = randomBoolean(); if (!equals) { equals = true; if (rarely()) { equals = false; account = "another account"; } if (rarely()) { equals = false; // cover the special case that randomIssueDefaults() left an empty map here as // well as in the action1, so that those would be equal - make sure they are not fields = JiraAccountTests.randomIssueDefaults(); while (fields.equals(action1.fields)) { fields = JiraAccountTests.randomIssueDefaults(); } } if (rarely()) { equals = false; // another low probability case, that a random proxy is exactly the same including // port number proxy = randomHttpProxy(); while (proxy.equals(action1.proxy)) { proxy = randomHttpProxy(); } } } JiraAction action2 = new JiraAction(account, fields, proxy); assertThat(action1.equals(action2), is(equals)); }
From source file:org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass.java
@SuppressWarnings("unchecked") private Map getMergedConfigurationMap(String propertyName) { Map configurationMap = getStaticPropertyValue(propertyName, Map.class); if (configurationMap == null) { configurationMap = new HashMap(); }//from w w w . j a v a 2 s. co m Class<?> theClass = getClazz(); while (theClass != Object.class) { theClass = theClass.getSuperclass(); ClassPropertyFetcher propertyFetcher = ClassPropertyFetcher.forClass(theClass); Map superRelationshipMap = propertyFetcher.getStaticPropertyValue(propertyName, Map.class); if (superRelationshipMap != null && !superRelationshipMap.equals(configurationMap)) { configurationMap.putAll(superRelationshipMap); } } return configurationMap; }
From source file:org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl.java
private synchronized void flushConfig(Map<String, RSGroupInfo> newGroupMap) throws IOException { Map<TableName, String> newTableMap; // For offline mode persistence is still unavailable // We're refreshing in-memory state but only for default servers if (!isOnline()) { Map<String, RSGroupInfo> m = Maps.newHashMap(rsGroupMap); RSGroupInfo oldDefaultGroup = m.remove(RSGroupInfo.DEFAULT_GROUP); RSGroupInfo newDefaultGroup = newGroupMap.remove(RSGroupInfo.DEFAULT_GROUP); if (!m.equals(newGroupMap) || !oldDefaultGroup.getTables().equals(newDefaultGroup.getTables())) { throw new IOException("Only default servers can be updated during offline mode"); }// ww w . ja v a 2 s.co m newGroupMap.put(RSGroupInfo.DEFAULT_GROUP, newDefaultGroup); rsGroupMap = newGroupMap; return; } newTableMap = flushConfigTable(newGroupMap); // make changes visible since it has been // persisted in the source of truth rsGroupMap = Collections.unmodifiableMap(newGroupMap); tableMap = Collections.unmodifiableMap(newTableMap); try { String groupBasePath = ZKUtil.joinZNode(watcher.baseZNode, rsGroupZNode); ZKUtil.createAndFailSilent(watcher, groupBasePath, ProtobufMagic.PB_MAGIC); List<ZKUtil.ZKUtilOp> zkOps = new ArrayList<ZKUtil.ZKUtilOp>(newGroupMap.size()); for (String groupName : prevRSGroups) { if (!newGroupMap.containsKey(groupName)) { String znode = ZKUtil.joinZNode(groupBasePath, groupName); zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode)); } } for (RSGroupInfo RSGroupInfo : newGroupMap.values()) { String znode = ZKUtil.joinZNode(groupBasePath, RSGroupInfo.getName()); RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(RSGroupInfo); LOG.debug("Updating znode: " + znode); ZKUtil.createAndFailSilent(watcher, znode); zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode)); zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode, ProtobufUtil.prependPBMagic(proto.toByteArray()))); } LOG.debug("Writing ZK GroupInfo count: " + zkOps.size()); ZKUtil.multiOrSequential(watcher, zkOps, false); } catch (KeeperException e) { LOG.error("Failed to write to rsGroupZNode", e); master.abort("Failed to write to rsGroupZNode", e); throw new IOException("Failed to write to rsGroupZNode", e); } prevRSGroups.clear(); prevRSGroups.addAll(newGroupMap.keySet()); }
From source file:com.inmobi.conduit.local.LocalStreamServiceTest.java
private void validateExpectedOutput(Set<String> results, Set<String> trashPaths, Map<String, String> checkPointPaths) { assert results.equals(expectedResults); assert trashPaths.equals(expectedTrashPaths); assert checkPointPaths.equals(expectedCheckPointPaths); }
From source file:com.taobao.tddl.jdbc.atom.TAtomDsConfHandle.java
/** * flushreCreate//from w w w.j a v a 2 s . c o m * * @param defaultDbConfManager */ private void registerAppDbConfListener(DbConfManager dbConfManager) { dbConfManager.registerAppDbConfListener(new ConfigDataListener() { public void onDataRecieved(String dataId, String data) { logger.error("[AppConf HandleData] dataId : " + dataId + " data: " + data); if (null == data || TStringUtil.isBlank(data)) { return; } lock.lock(); try { String appConfStr = data; TAtomDsConfDO tmpConf = TAtomConfParser.parserTAtomDsConfDO(null, appConfStr); TAtomDsConfDO newConf = TAtomDsConfHandle.this.runTimeConf.clone(); // set newConf.setUserName(tmpConf.getUserName()); newConf.setMinPoolSize(tmpConf.getMinPoolSize()); newConf.setMaxPoolSize(tmpConf.getMaxPoolSize()); newConf.setIdleTimeout(tmpConf.getIdleTimeout()); newConf.setBlockingTimeout(tmpConf.getBlockingTimeout()); newConf.setPreparedStatementCacheSize(tmpConf.getPreparedStatementCacheSize()); newConf.setConnectionProperties(tmpConf.getConnectionProperties()); newConf.setOracleConType(tmpConf.getOracleConType()); // 3 newConf.setWriteRestrictTimes(tmpConf.getWriteRestrictTimes()); newConf.setReadRestrictTimes(tmpConf.getReadRestrictTimes()); newConf.setThreadCountRestrict(tmpConf.getThreadCountRestrict()); newConf.setTimeSliceInMillis(tmpConf.getTimeSliceInMillis()); // overConfByLocal(TAtomDsConfHandle.this.localConf, newConf); // tAtomDsConfDO LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(newConf, TAtomConstants .getDbNameStr(TAtomDsConfHandle.this.appName, TAtomDsConfHandle.this.dbKey)); // if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) { logger.error("[GlobaConfError] dataSource Prams Error! dataId : " + dataId + " config : " + data); return; } boolean isNeedReCreate = isNeedReCreate(TAtomDsConfHandle.this.runTimeConf, newConf); if (isNeedReCreate) { try { TAtomDsConfHandle.this.jbossDataSource.destroy(); logger.warn("[destroy OldDataSource] dataId : " + dataId); LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory .createLocalTxDataSource(localTxDataSourceDO); logger.warn("[create newDataSource] dataId : " + dataId); TAtomDsConfHandle.this.jbossDataSource = localTxDataSource; clearDataSourceWrapper(); TAtomDsConfHandle.this.runTimeConf = newConf; } catch (Exception e) { logger.error("[Flsh AppConf Error] reCreate dataSource Error ! dataId: " + dataId, e); } } else { boolean isNeedFlush = isNeedFlush(TAtomDsConfHandle.this.runTimeConf, newConf); /** * runTimeConfwrapDataSource */ boolean isRestrictChange = isRestrictChange(TAtomDsConfHandle.this.runTimeConf, newConf); if (isNeedFlush) { TAtomDsConfHandle.this.jbossDataSource .setConnectionURL(localTxDataSourceDO.getConnectionURL()); TAtomDsConfHandle.this.jbossDataSource.setUserName(localTxDataSourceDO.getUserName()); try { // TAtomDsConfHandle.this.flushDataSource(); // TAtomDsConfHandle.this.runTimeConf = newConf; clearDataSourceWrapper(); } catch (Exception e) { logger.error("[Flash GlobaConf Error] flush dataSource Error !", e); } } else if (isRestrictChange) { TAtomDsConfHandle.this.runTimeConf = newConf; clearDataSourceWrapper(); } } } finally { lock.unlock(); } } private boolean isNeedReCreate(TAtomDsConfDO runConf, TAtomDsConfDO newConf) { boolean needReCreate = false; if (AtomDbTypeEnum.ORACLE == newConf.getDbTypeEnum()) { Map<String, String> newProp = newConf.getConnectionProperties(); Map<String, String> runProp = runConf.getConnectionProperties(); if (!runProp.equals(newProp)) { return true; } } if (runConf.getMinPoolSize() != newConf.getMinPoolSize()) { return true; } if (runConf.getMaxPoolSize() != newConf.getMaxPoolSize()) { return true; } if (runConf.getBlockingTimeout() != newConf.getBlockingTimeout()) { return true; } if (runConf.getIdleTimeout() != newConf.getIdleTimeout()) { return true; } if (runConf.getPreparedStatementCacheSize() != newConf.getPreparedStatementCacheSize()) { return true; } return needReCreate; } private boolean isNeedFlush(TAtomDsConfDO runConf, TAtomDsConfDO newConf) { boolean needFlush = false; if (AtomDbTypeEnum.MYSQL == newConf.getDbTypeEnum()) { Map<String, String> newProp = newConf.getConnectionProperties(); Map<String, String> runProp = runConf.getConnectionProperties(); if (!runProp.equals(newProp)) { return true; } } if (!TStringUtil.equals(runConf.getUserName(), newConf.getUserName())) { return true; } if (!TStringUtil.equals(runConf.getPasswd(), newConf.getPasswd())) { return true; } return needFlush; } private boolean isRestrictChange(TAtomDsConfDO runConf, TAtomDsConfDO newConf) { if (runConf.getReadRestrictTimes() != newConf.getReadRestrictTimes()) { return true; } if (runConf.getWriteRestrictTimes() != newConf.getWriteRestrictTimes()) { return true; } if (runConf.getThreadCountRestrict() != newConf.getThreadCountRestrict()) { return true; } if (runConf.getTimeSliceInMillis() != newConf.getTimeSliceInMillis()) { return true; } return false; } }); }