List of usage examples for java.util NavigableMap put
V put(K key, V value);
From source file:com.alibaba.wasp.fserver.EntityGroup.java
/** * Make insert action into transaction;/* www.j a va2 s. c o m*/ * * @param action * insert action * @param transaction * transaction * @throws java.io.IOException * @throws com.alibaba.wasp.storage.StorageTableNotFoundException */ private void prepareInsertEntity(InsertAction action, Transaction transaction) throws IOException, StorageTableNotFoundException { long before = EnvironmentEdgeManager.currentTimeMillis(); RowBuilder builder = RowBuilder.build(); TableSchemaCacheReader metaReader = TableSchemaCacheReader.getInstance(this.conf); LinkedHashMap<String, Index> indexs = metaReader.getSchema(action.getFTableName()).getIndex(); if (LOG.isDebugEnabled()) { LOG.debug("prepareInsertEntity indexs:" + indexs.values()); } NavigableMap<byte[], NavigableMap<byte[], byte[]>> set = new TreeMap<byte[], NavigableMap<byte[], byte[]>>( Bytes.BYTES_COMPARATOR); for (ColumnStruct col : action.getColumns()) { byte[] family = Bytes.toBytes(col.getFamilyName()); NavigableMap<byte[], byte[]> cols = set.get(family); if (cols == null) { cols = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR); } set.put(family, cols); cols.put(Bytes.toBytes(col.getColumnName()), col.getValue()); } String entityTableName = StorageTableNameBuilder.buildEntityTableName(action.getFTableName()); // entity put Put entityPut = builder.buildPut(action); transaction.addEntity(ProtobufUtil.toMutate(MutateType.PUT, entityPut, entityTableName)); storageServices.checkRowExistsBeforeInsert(action, entityTableName, entityPut); // index put if (indexs != null) { for (Index index : indexs.values()) { Pair<byte[], String> indexPut = builder.buildIndexKey(index, set, entityPut.getRow()); if (indexPut != null) { Put put = new Put(indexPut.getFirst()); put.add(FConstants.INDEX_STORING_FAMILY_BYTES, FConstants.INDEX_STORE_ROW_QUALIFIER, entityPut.getRow()); for (Entry<String, Field> entry : index.getStoring().entrySet()) { ColumnStruct storing = action.getName2Column().get(entry.getKey()); if (storing != null) { put.add(FConstants.INDEX_STORING_FAMILY_BYTES, Bytes.toBytes(entry.getKey()), storing.getValue()); } } transaction.addEntity(ProtobufUtil.toMutate(MutateType.PUT, put, indexPut.getSecond())); } } } if (this.metricsEntityGroup != null) { this.metricsEntityGroup.updatePrepareInsertEntity(EnvironmentEdgeManager.currentTimeMillis() - before); } }
From source file:com.alibaba.wasp.client.WaspAdmin.java
/** * Gets all the entityGroups and their address for this table. * <p>//from w w w . j a va2s. com * This is mainly useful for the MapReduce integration. * * @return A map of EntityGroupInfo with it's server address * @throws java.io.IOException * if a remote or network exception occurs */ public NavigableMap<EntityGroupInfo, ServerName> getEntityGroupLocations(final byte[] tableName) throws IOException { MasterAdminProtos.GetEntityGroupsResponse res = execute( new MasterAdminCallable<MasterAdminProtos.GetEntityGroupsResponse>() { @Override public MasterAdminProtos.GetEntityGroupsResponse call() throws ServiceException { MasterAdminProtos.GetEntityGroupsRequest req = RequestConverter .buildGetEntityGroupsRequest(tableName); return this.masterAdmin.getEntityGroups(null, req); } }); NavigableMap<EntityGroupInfo, ServerName> entityGroups = null; if (!res.getEntityGroupList().isEmpty()) { entityGroups = new TreeMap<EntityGroupInfo, ServerName>(); for (MasterAdminProtos.GetEntityGroupResponse response : res.getEntityGroupList()) { entityGroups.put(EntityGroupInfo.convert(response.getEgInfo()), ServerName.convert(response.getServerName())); } } return entityGroups; }
From source file:com.mirth.connect.connectors.http.HttpReceiver.java
@Override public void onStart() throws ConnectorTaskException { String channelId = getChannelId(); String channelName = getChannel().getName(); host = replacer.replaceValues(connectorProperties.getListenerConnectorProperties().getHost(), channelId, channelName);//from w w w. jav a2 s. c o m port = NumberUtils.toInt(replacer.replaceValues( connectorProperties.getListenerConnectorProperties().getPort(), channelId, channelName)); timeout = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getTimeout(), channelId, channelName), 0); // Initialize contextPath to "" or its value after replacements String contextPath = (connectorProperties.getContextPath() == null ? "" : replacer.replaceValues(connectorProperties.getContextPath(), channelId, channelName)).trim(); /* * Empty string and "/" are both valid and equal functionally. However if there is a * resource defined, we need to make sure that the context path starts with a slash and * doesn't end with one. */ if (!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } if (contextPath.endsWith("/")) { contextPath = contextPath.substring(0, contextPath.length() - 1); } try { server = new Server(); configuration.configureReceiver(this); HandlerCollection handlers = new HandlerCollection(); Handler serverHandler = handlers; // Add handlers for each static resource if (connectorProperties.getStaticResources() != null) { NavigableMap<String, List<HttpStaticResource>> staticResourcesMap = new TreeMap<String, List<HttpStaticResource>>(); // Add each static resource to a map first to allow sorting and deduplication for (HttpStaticResource staticResource : connectorProperties.getStaticResources()) { String resourceContextPath = replacer.replaceValues(staticResource.getContextPath(), channelId, channelName); Map<String, List<String>> queryParameters = new HashMap<String, List<String>>(); // If query parameters were specified, extract them here int queryIndex = resourceContextPath.indexOf('?'); if (queryIndex >= 0) { String query = resourceContextPath.substring(queryIndex + 1); resourceContextPath = resourceContextPath.substring(0, queryIndex); for (NameValuePair param : URLEncodedUtils.parse(query, Charset.defaultCharset())) { List<String> currentValue = queryParameters.get(param.getName()); String value = StringUtils.defaultString(param.getValue()); if (currentValue == null) { currentValue = new ArrayList<String>(); queryParameters.put(param.getName(), currentValue); } currentValue.add(value); } } // We always want to append resources starting with "/" to the base context path if (resourceContextPath.endsWith("/")) { resourceContextPath = resourceContextPath.substring(0, resourceContextPath.length() - 1); } if (!resourceContextPath.startsWith("/")) { resourceContextPath = "/" + resourceContextPath; } resourceContextPath = contextPath + resourceContextPath; List<HttpStaticResource> staticResourcesList = staticResourcesMap.get(resourceContextPath); if (staticResourcesList == null) { staticResourcesList = new ArrayList<HttpStaticResource>(); staticResourcesMap.put(resourceContextPath, staticResourcesList); } staticResourcesList .add(new HttpStaticResource(resourceContextPath, staticResource.getResourceType(), staticResource.getValue(), staticResource.getContentType(), queryParameters)); } // Iterate through each context path in reverse so that more specific contexts take precedence for (List<HttpStaticResource> staticResourcesList : staticResourcesMap.descendingMap().values()) { for (HttpStaticResource staticResource : staticResourcesList) { logger.debug("Adding static resource handler for context path: " + staticResource.getContextPath()); ContextHandler resourceContextHandler = new ContextHandler(); resourceContextHandler.setContextPath(staticResource.getContextPath()); // This allows resources to be requested without a relative context path (e.g. "/") resourceContextHandler.setAllowNullPathInfo(true); resourceContextHandler.setHandler(new StaticResourceHandler(staticResource)); handlers.addHandler(resourceContextHandler); } } } // Add the main request handler ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath(contextPath); contextHandler.setHandler(new RequestHandler()); handlers.addHandler(contextHandler); // Wrap the handler collection in a security handler if needed if (authenticatorProvider != null) { serverHandler = createSecurityHandler(handlers); } server.setHandler(serverHandler); logger.debug("starting HTTP server with address: " + host + ":" + port); server.start(); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.IDLE)); } catch (Exception e) { eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.FAILURE)); throw new ConnectorTaskException("Failed to start HTTP Listener", e); } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testDescendingKeySet() { K[] keys = getSortedKeys();//from w w w . ja va2s . co m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); NavigableSet<K> keySet = map.descendingKeySet(); _assertEquals(keySet, map.descendingKeySet()); map.put(keys[1], values[1]); map.put(keys[2], values[2]); _assertEquals(reverseCollection(keySet), keySet); _assertEquals(map.keySet(), keySet.descendingSet()); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testLastKey_after_subMap() { K[] keys = getSortedKeys();/*from ww w.jav a2 s . c o m*/ V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); map.put(keys[1], values[1]); map.put(keys[2], values[2]); SortedMap<K, V> subMap = map; K firstKey = subMap.firstKey(); for (int i = 0; i < map.size(); i++) { K lastKey = subMap.lastKey(); subMap = subMap.subMap(firstKey, lastKey); } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testPutLjava_lang_ObjectLjava_lang_Object() { K[] keys = getSortedKeys();// ww w .j a v a 2 s. c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); assertNull(map.put(keys[0], values[0])); assertTrue(map.get(keys[0]) == values[0]); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testNavigableKeySet_viewRemove() { K[] keys = getSortedKeys();// w w w . j a va2 s. co m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); map.put(keys[1], values[1]); Set<K> keySet = map.navigableKeySet(); assertEquals(2, keySet.size()); map.remove(keys[1]); assertEquals(1, keySet.size()); map.put(keys[1], values[1]); keySet.remove(keys[0]); assertEquals(1, map.size()); assertEquals(1, keySet.size()); assertEquals(keys[1], keySet.iterator().next()); keySet.clear(); _assertEmpty(map); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testDescendingKeySet_viewRemove() { K[] keys = getSortedKeys();//from www . java2 s .c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); map.put(keys[1], values[1]); Set<K> keySet = map.descendingKeySet(); assertEquals(2, keySet.size()); map.remove(keys[1]); assertEquals(1, keySet.size()); map.put(keys[1], values[1]); keySet.remove(keys[0]); assertEquals(1, map.size()); assertEquals(1, keySet.size()); assertEquals(keys[1], keySet.iterator().next()); keySet.clear(); assertEquals(0, map.size()); assertEquals(0, keySet.size()); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
@SuppressWarnings("ModifyingCollectionWithItself") public void testNavigableKeySet_viewPut() { K[] keys = getSortedKeys();//from w w w.j a va 2 s. c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); Set<K> keySet = map.navigableKeySet(); assertEquals(1, keySet.size()); map.put(keys[1], values[1]); assertEquals(2, keySet.size()); try { keySet.add(keys[2]); fail(); } catch (Exception e) { // java.util.NavigableMap.navigableKeySet() does not support add } try { keySet.addAll(keySet); fail(); } catch (Exception e) { // java.util.NavigableMap.navigableKeySet() does not support addAll } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
@SuppressWarnings("ModifyingCollectionWithItself") public void testDescendingKeySet_viewPut() { K[] keys = getSortedKeys();// w w w. ja v a 2 s . c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); map.put(keys[0], values[0]); Set<K> keySet = map.descendingKeySet(); assertEquals(1, keySet.size()); map.put(keys[1], values[1]); assertEquals(2, keySet.size()); try { keySet.add(keys[2]); fail(); } catch (Exception e) { // java.util.NavigableMap.navigableKeySet() does not support add } try { keySet.addAll(keySet); fail(); } catch (Exception e) { // java.util.NavigableMap.navigableKeySet() does not support addAll } }