List of usage examples for org.apache.commons.lang3.tuple MutablePair MutablePair
public MutablePair(final L left, final R right)
From source file:org.apache.giraph.ooc.DiskBackedPartitionStore.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings("SF_SWITCH_FALLTHROUGH") public void addPartitionVertices(Integer partitionId, ExtendedDataOutput extendedDataOutput) { if (!isInitialized.get()) { initialize();/*from w w w. j av a 2 s .c o m*/ } MetaPartition meta = new MetaPartition(partitionId); MetaPartition temp = partitions.putIfAbsent(partitionId, meta); if (temp != null) { meta = temp; } boolean createPartition = false; synchronized (meta) { switch (meta.getState()) { case INIT: Partition<I, V, E> partition = conf.createPartition(partitionId, context); meta.setPartition(partition); // Look at the comments in 'addPartitionVertices' for why we set the // this to true. meta.setProcessed(true); numPartitionsInMem.getAndIncrement(); meta.setState(State.INACTIVE); synchronized (processedPartitions) { processedPartitions.get(State.INACTIVE).add(partitionId); processedPartitions.notifyAll(); } createPartition = true; // Continue to INACTIVE case to add the vertices to the partition // CHECKSTYLE: stop FallThrough case INACTIVE: // CHECKSTYLE: resume FallThrough meta.getPartition().addPartitionVertices(new VertexIterator<I, V, E>(extendedDataOutput, conf)); break; case IN_TRANSIT: case ON_DISK: // Adding vertices to in-memory buffer of the partition List<ExtendedDataOutput> vertices = new ArrayList<ExtendedDataOutput>(); vertices.add(extendedDataOutput); int length = extendedDataOutput.getPos(); Pair<Integer, List<ExtendedDataOutput>> newPair = new MutablePair<>(length, vertices); vertexBufferRWLock.readLock().lock(); Pair<Integer, List<ExtendedDataOutput>> oldPair = pendingInputVertices.putIfAbsent(partitionId, newPair); if (oldPair != null) { synchronized (oldPair) { MutablePair<Integer, List<ExtendedDataOutput>> pair = (MutablePair<Integer, List<ExtendedDataOutput>>) oldPair; pair.setLeft(pair.getLeft() + length); pair.getRight().add(extendedDataOutput); } } vertexBufferRWLock.readLock().unlock(); // In the case that the number of partitions is asked to be fixed by the // user, we should offload the edge store as necessary. if (isNumPartitionsFixed && pendingInputVertices.get(partitionId).getLeft() > minBuffSize) { try { spillPartitionInputVertexBuffer(partitionId); } catch (IOException e) { throw new IllegalStateException("addPartitionVertices: spilling " + "vertex buffer for partition " + partitionId + " failed!"); } } break; default: throw new IllegalStateException( "illegal state " + meta.getState() + " for partition " + meta.getId()); } } // If creation of a new partition is violating the policy of maximum number // of partitions in memory, we should spill a partition to disk. if (createPartition && numPartitionsInMem.get() > maxPartitionsInMem.get()) { swapOnePartitionToDisk(); } }
From source file:org.apache.hive.storage.jdbc.spitter.DateIntervalSplitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {//from w w w .j a v a 2 s .c o m List<MutablePair<String, String>> intervals = new ArrayList<>(); Date dateLower = Date.valueOf(lowerBound); Date dateUpper = Date.valueOf(upperBound); double dateInterval = (dateUpper.getTime() - dateLower.getTime()) / (double) numPartitions; Date splitDateLower, splitDateUpper; for (int i = 0; i < numPartitions; i++) { splitDateLower = new Date(Math.round(dateLower.getTime() + dateInterval * i)); splitDateUpper = new Date(Math.round(dateLower.getTime() + dateInterval * (i + 1))); if (splitDateLower.compareTo(splitDateUpper) < 0) { intervals .add(new MutablePair<String, String>(splitDateLower.toString(), splitDateUpper.toString())); } } return intervals; }
From source file:org.apache.hive.storage.jdbc.spitter.DecimalIntervalSplitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {//w w w .j a va 2 s.co m List<MutablePair<String, String>> intervals = new ArrayList<>(); DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo; int scale = decimalTypeInfo.getScale(); BigDecimal decimalLower = new BigDecimal(lowerBound); BigDecimal decimalUpper = new BigDecimal(upperBound); BigDecimal decimalInterval = (decimalUpper.subtract(decimalLower)).divide(new BigDecimal(numPartitions), MathContext.DECIMAL64); BigDecimal splitDecimalLower, splitDecimalUpper; for (int i = 0; i < numPartitions; i++) { splitDecimalLower = decimalLower.add(decimalInterval.multiply(new BigDecimal(i))).setScale(scale, RoundingMode.HALF_EVEN); splitDecimalUpper = decimalLower.add(decimalInterval.multiply(new BigDecimal(i + 1))).setScale(scale, RoundingMode.HALF_EVEN); if (splitDecimalLower.compareTo(splitDecimalUpper) < 0) { intervals.add(new MutablePair<String, String>(splitDecimalLower.toPlainString(), splitDecimalUpper.toPlainString())); } } return intervals; }
From source file:org.apache.hive.storage.jdbc.spitter.DoubleIntervalSplitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {//from w w w . j av a2s.c o m List<MutablePair<String, String>> intervals = new ArrayList<>(); double doubleLower = Double.parseDouble(lowerBound); double doubleUpper = Double.parseDouble(upperBound); double doubleInterval = (doubleUpper - doubleLower) / (double) numPartitions; double splitDoubleLower, splitDoubleUpper; for (int i = 0; i < numPartitions; i++) { splitDoubleLower = doubleLower + doubleInterval * i; splitDoubleUpper = doubleLower + doubleInterval * (i + 1); if (splitDoubleUpper > splitDoubleLower) { intervals.add(new MutablePair<String, String>(Double.toString(splitDoubleLower), Double.toString(splitDoubleUpper))); } } return intervals; }
From source file:org.apache.hive.storage.jdbc.spitter.LongIntervalSpitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {//from w ww . j a v a2s.co m List<MutablePair<String, String>> intervals = new ArrayList<>(); long longLower = Long.parseLong(lowerBound); long longUpper = Long.parseLong(upperBound); double longInterval = (longUpper - longLower) / (double) numPartitions; long splitLongLower, splitLongUpper; for (int i = 0; i < numPartitions; i++) { splitLongLower = Math.round(longLower + longInterval * i); splitLongUpper = Math.round(longLower + longInterval * (i + 1)); if (splitLongUpper > splitLongLower) { intervals.add(new MutablePair<String, String>(Long.toString(splitLongLower), Long.toString(splitLongUpper))); } } return intervals; }
From source file:org.apache.hive.storage.jdbc.spitter.TimestampIntervalSplitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {//from ww w.j a v a 2 s . co m List<MutablePair<String, String>> intervals = new ArrayList<>(); Timestamp timestampLower = Timestamp.valueOf(lowerBound); Timestamp timestampUpper = Timestamp.valueOf(upperBound); // Note nano is not fully represented as the precision limit double timestampInterval = (timestampUpper.getTime() - timestampLower.getTime()) / (double) numPartitions; Timestamp splitTimestampLower, splitTimestampUpper; for (int i = 0; i < numPartitions; i++) { splitTimestampLower = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval * i)); splitTimestampUpper = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval * (i + 1))); if (splitTimestampLower.compareTo(splitTimestampUpper) < 0) { intervals.add(new MutablePair<String, String>(splitTimestampLower.toString(), splitTimestampUpper.toString())); } } return intervals; }
From source file:org.apache.openejb.server.hessian.TomcatHessianRegistry.java
@Override public String deploy(final ClassLoader loader, final HessianServer listener, final String hostname, final String app, final String authMethod, final String transportGuarantee, final String realmName, final String name) throws URISyntaxException { Container host = engine.findChild(hostname); if (host == null) { host = engine.findChild(engine.getDefaultHost()); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?"); }/*from w w w. j a va 2 s.c o m*/ } final String contextRoot = contextName(app); Context context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot); if (fakeContext != null) { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } else { context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { fakeContext = fakeContexts.get(contextRoot); if (fakeContext == null) { context = createNewContext(loader, authMethod, transportGuarantee, realmName, app); fakeContext = new MutablePair<>(context, 1); fakeContexts.put(contextRoot, fakeContext); } else { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } } } } final String servletMapping = generateServletPath(name); Wrapper wrapper = Wrapper.class.cast(context.findChild(servletMapping)); if (wrapper != null) { throw new IllegalArgumentException("Servlet " + servletMapping + " in web application context " + context.getName() + " already exists"); } wrapper = context.createWrapper(); wrapper.setName(HESSIAN.replace("/", "") + "_" + name); wrapper.setServlet(new OpenEJBHessianServlet(listener)); context.addChild(wrapper); context.addServletMapping(servletMapping, wrapper.getName()); if ("BASIC".equals(authMethod) && StandardContext.class.isInstance(context)) { final StandardContext standardContext = StandardContext.class.cast(context); boolean found = false; for (final Valve v : standardContext.getPipeline().getValves()) { if (LimitedBasicValve.class.isInstance(v) || BasicAuthenticator.class.isInstance(v)) { found = true; break; } } if (!found) { standardContext.addValve(new LimitedBasicValve()); } } final List<String> addresses = new ArrayList<>(); for (final Connector connector : connectors) { for (final String mapping : wrapper.findMappings()) { final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), contextRoot + mapping, null, null); addresses.add(address.toString()); } } return HttpUtil.selectSingleAddress(addresses); }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
public Map<String, MutablePair<String, CommentsNodeImpl>> copyMap(CommentsNodeImpl parent) { Map<String, MutablePair<String, CommentsNodeImpl>> result = new HashMap<>(this.dataMap.size()); for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet()) { String keyToCpy = entry.getKey(); MutablePair<String, CommentsNodeImpl> valueToCpy = entry.getValue(); CommentsNodeImpl nodeToCpy = valueToCpy.getRight(); CommentsNodeImpl copiedNode;/*ww w . j av a 2 s. c o m*/ if (nodeToCpy == null) { copiedNode = null; } else { copiedNode = new CommentsNodeImpl(parent); copiedNode.dataMap.putAll(nodeToCpy.copyMap(parent)); } MutablePair<String, CommentsNodeImpl> copied = new MutablePair<>(valueToCpy.getLeft(), copiedNode); result.put(keyToCpy, copied); } return result; }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@SuppressWarnings("unchecked") Map<String, MutablePair<String, ?>> buildMap() { Map<String, MutablePair<String, ?>> resultMap = new LinkedHashMap<>(this.dataMap.size()); for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet()) { MutablePair<String, CommentsNodeImpl> value = entry.getValue(); CommentsNodeImpl right = value.getRight(); String left = value.getLeft(); if ((right == null) && (left == null)) { continue; }// w w w. j a va 2 s. c om Map<String, MutablePair<String, ?>> rightMap = null; if (right != null) { rightMap = right.buildMap(); if (rightMap.isEmpty()) { rightMap = null; if (left == null) { continue; } } } resultMap.put(entry.getKey(), new MutablePair<>(left, rightMap)); } return resultMap; }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public void setComment(String path, @Nullable String comment) { MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.computeIfAbsent(path, k -> new MutablePair<>(null, null)); if (comment == null) { nodePair.setLeft(null);// w ww. ja v a 2s.c o m return; } nodePair.setLeft(comment); }