public boolean addBinaryStateUnsafeIndexing(char key) { if (key == 0 || key == zeroMask) { return false; } char[] keys = set; long capacityMask = (long) (keys.length - 1); long index = ((long) Primitives.hashCode(key)) & capacityMask; long offset = index << CHAR_SCALE_SHIFT; char cur = U.getChar(keys, CHAR_BASE + offset); keyAbsent: if (cur != 0) { if (cur == key) { return false; } else { long capacityOffsetMask = capacityMask << CHAR_SCALE_SHIFT; while (true) { offset = (offset + CHAR_SCALE) & capacityOffsetMask; if ((cur = U.getChar(keys, CHAR_BASE + offset)) == 0) { break keyAbsent; } else if (cur == key) { return false; } } } } // key is absent U.putChar(keys, CHAR_BASE + offset, key); size++; return true; }
/** * Log task mapped. * * @param log Logger. * @param clazz Task class. * @param nodes Mapped nodes. */ public static void logMapped( @Nullable IgniteLogger log, Class<?> clazz, Collection<ClusterNode> nodes) { log0( log, U.currentTimeMillis(), String.format("[%s]: MAPPED: %s", clazz.getSimpleName(), U.toShortString(nodes))); }
public int indexBinaryStateUnsafeIndexing(char key) { if (key != 0 && key != zeroMask) { char[] keys = set; long capacityMask = (long) (keys.length - 1); long index = ((long) Primitives.hashCode(key)) & capacityMask; long offset = index << CHAR_SCALE_SHIFT; long CHAR_BASE = UnsafeConstants.CHAR_BASE; char cur = U.getChar(keys, CHAR_BASE + offset); if (cur == key) { return (int) index; } else { if (cur == 0) { return -1; } else { long capacityOffsetMask = capacityMask << CHAR_SCALE_SHIFT; while (true) { offset = (offset + CHAR_SCALE) & capacityOffsetMask; if ((cur = U.getChar(keys, CHAR_BASE + offset)) == key) { return (int) (offset >> CHAR_SCALE_SHIFT); } else if (cur == 0) { return -1; } } } } } else { return -1; } }
/** * Gets license version 2 data for sign. * * @param lic GridGain license version 2. * @return Data for sign. */ public static byte[] getDataV2ForSign(GridLicenseV2 lic) { assert lic != null; try { return new SB() .a(lic.getVersion()) .a(lic.getId()) .a(lic.getIssueDate() != null ? U.format(lic.getIssueDate(), DATE_PTRN) : "") .a(lic.getIssueOrganization()) .a(lic.getUserOrganization()) .a(lic.getUserWww()) .a(lic.getUserEmail()) .a(lic.getUserName()) .a(lic.getLicenseNote()) .a(lic.getVersionRegexp()) .a(lic.getType()) .a(lic.getExpireDate() != null ? U.format(lic.getExpireDate(), DATE_PTRN) : "") .a(lic.getMeteringKey1()) .a(lic.getMeteringKey2()) .a(lic.getMaxCpus()) .a(lic.getMaxComputers()) .a(lic.getMaxNodes()) .a(lic.getMaxUpTime()) .toString() .getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new GridRuntimeException(e); } }
/** * Decodes value from a given byte array to the object according to the flags given. * * @param flags Flags. * @param bytes Byte array to decode. * @return Decoded value. * @throws GridException If deserialization failed. */ private Object decodeObj(short flags, byte[] bytes) throws GridException { assert bytes != null; if ((flags & SERIALIZED_FLAG) != 0) return jdkMarshaller.unmarshal(new ByteArrayInputStream(bytes), null); int masked = flags & 0xff00; switch (masked) { case BOOLEAN_FLAG: return bytes[0] == '1'; case INT_FLAG: return U.bytesToInt(bytes, 0); case LONG_FLAG: return U.bytesToLong(bytes, 0); case DATE_FLAG: return new Date(U.bytesToLong(bytes, 0)); case BYTE_FLAG: return bytes[0]; case FLOAT_FLAG: return Float.intBitsToFloat(U.bytesToInt(bytes, 0)); case DOUBLE_FLAG: return Double.longBitsToDouble(U.bytesToLong(bytes, 0)); case BYTE_ARR_FLAG: return bytes; default: return new String(bytes); } }
/** @param workTokDir Token directory (common for multiple nodes). */ private void cleanupResources(File workTokDir) { RandomAccessFile lockFile = null; FileLock lock = null; try { lockFile = new RandomAccessFile(new File(workTokDir, LOCK_FILE_NAME), "rw"); lock = lockFile.getChannel().lock(); if (lock != null) processTokenDirectory(workTokDir); else if (log.isDebugEnabled()) log.debug( "Token directory is being processed concurrently: " + workTokDir.getAbsolutePath()); } catch (OverlappingFileLockException ignored) { if (log.isDebugEnabled()) log.debug( "Token directory is being processed concurrently: " + workTokDir.getAbsolutePath()); } catch (FileLockInterruptionException ignored) { Thread.currentThread().interrupt(); } catch (IOException e) { U.error(log, "Failed to process directory: " + workTokDir.getAbsolutePath(), e); } finally { U.releaseQuiet(lock); U.closeQuiet(lockFile); } }
/** @param e Error. */ void onError(Throwable e) { tx.commitError(e); if (err.compareAndSet(null, e)) { boolean marked = tx.setRollbackOnly(); if (e instanceof GridCacheTxRollbackException) { if (marked) { try { tx.rollback(); } catch (GridException ex) { U.error(log, "Failed to automatically rollback transaction: " + tx, ex); } } } else if (tx.implicit() && tx.isSystemInvalidate()) { // Finish implicit transaction on heuristic error. try { tx.close(); } catch (GridException ex) { U.error(log, "Failed to invalidate transaction: " + tx, ex); } } onComplete(); } }
@Override public void generate(Shell parentShell, IType objectClass, CommandIdentifier commandIdentifier) { LinkedHashSet<MethodSkeleton<U>> methodSkeletons = methodSkeletonManager.getMethodSkeletons(commandIdentifier); LinkedHashSet<StrategyIdentifier> strategyIdentifiers = methodContentManager.getStrategiesIntersection(methodSkeletons); try { Set<IMethod> excludedMethods = getExcludedMethods(objectClass, methodSkeletons); FieldDialog<U> dialog = dialogFactory.createDialog( parentShell, objectClass, excludedMethods, strategyIdentifiers); int returnCode = dialog.getDialog().open(); if (returnCode == Window.OK) { for (IMethod excludedMethod : excludedMethods) { excludedMethod.delete(true, null); } U data = dialog.getData(); StrategyIdentifier selectedContentStrategy = data.getSelectedStrategyIdentifier(); LinkedHashSet<Method<T, U>> methods = methodContentManager.getAllMethods(methodSkeletons, selectedContentStrategy); generateCode(parentShell, objectClass, data, methods); } } catch (Exception exception) { MessageDialog.openError(parentShell, "Method Generation Failed", exception.getMessage()); } }
void testUs() { for (U u : us) { u.f(); u.g(); u.toString(); } }
/** {@inheritDoc} */ @Nullable @Override public Map<? extends GridComputeJob, GridNode> map( List<GridNode> subgrid, @Nullable GridBiTuple<Set<UUID>, A> arg) throws GridException { assert arg != null; assert arg.get1() != null; start = U.currentTimeMillis(); boolean debug = debugState(g); if (debug) logStart(g.log(), getClass(), start); Set<UUID> nodeIds = arg.get1(); Map<GridComputeJob, GridNode> map = U.newHashMap(nodeIds.size()); try { taskArg = arg.get2(); for (GridNode node : subgrid) if (nodeIds.contains(node.id())) map.put(job(taskArg), node); return map; } finally { if (debug) logMapped(g.log(), getClass(), map.values()); } }
/** * Creates new HTTP requests handler. * * @param hnd Handler. * @param authChecker Authentication checking closure. * @param log Logger. */ GridJettyRestHandler( GridRestProtocolHandler hnd, GridClosure<String, Boolean> authChecker, GridLogger log) { assert hnd != null; assert log != null; this.hnd = hnd; this.log = log; this.authChecker = authChecker; // Init default page and favicon. try { initDefaultPage(); if (log.isDebugEnabled()) log.debug("Initialized default page."); } catch (IOException e) { U.warn(log, "Failed to initialize default page: " + e.getMessage()); } try { initFavicon(); if (log.isDebugEnabled()) log.debug( favicon != null ? "Initialized favicon, size: " + favicon.length : "Favicon is null."); } catch (IOException e) { U.warn(log, "Failed to initialize favicon: " + e.getMessage()); } }
/** * Message received callback. * * @param src Sender node ID. * @param msg Received message. * @return {@code True}. */ public boolean onMessageReceived(UUID src, GridHadoopMessage msg) { if (msg instanceof GridHadoopShuffleMessage) { GridHadoopShuffleMessage m = (GridHadoopShuffleMessage) msg; try { job(m.jobId()).onShuffleMessage(m); } catch (GridException e) { U.error(log, "Message handling failed.", e); } try { // Reply with ack. send0(src, new GridHadoopShuffleAck(m.id(), m.jobId())); } catch (GridException e) { U.error( log, "Failed to reply back to shuffle message sender [snd=" + src + ", msg=" + msg + ']', e); } } else if (msg instanceof GridHadoopShuffleAck) { GridHadoopShuffleAck m = (GridHadoopShuffleAck) msg; try { job(m.jobId()).onShuffleAck(m); } catch (GridException e) { U.error(log, "Message handling failed.", e); } } else throw new IllegalStateException( "Unknown message type received to Hadoop shuffle [src=" + src + ", msg=" + msg + ']'); return true; }
/** * @param cctx Context. * @param id Partition ID. */ @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition(GridCacheContext cctx, int id) { assert cctx != null; this.id = id; this.cctx = cctx; log = U.logger(cctx.kernalContext(), logRef, this); rent = new GridFutureAdapter<Object>() { @Override public String toString() { return "PartitionRentFuture [part=" + GridDhtLocalPartition.this + ", map=" + map + ']'; } }; map = new ConcurrentHashMap8<>(cctx.config().getStartSize() / cctx.affinity().partitions()); int delQueueSize = CU.isSystemCache(cctx.name()) ? 100 : Math.max(MAX_DELETE_QUEUE_SIZE / cctx.affinity().partitions(), 20); rmvQueue = new GridCircularBuffer<>(U.ceilPow2(delQueueSize)); }
private <T, U extends RestClientRootUrl & RestClientHeaders & RestClientSupport> RestCallResult doFireRequestWithPersistentAuth(Request<T> request, Response<T> response) { RestCallResult result = RestCallResult.OTHER_ERROR; U restClient = request.getRestClient(); try { Bundle bundle = accountPropertiesManager.getAuthToken().getResult(); if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) { String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (TextUtils.isEmpty(authToken)) { messageHelper.showError( ErrorType.REST_MAJOR, context.getString(R.string.rest_token_missing)); } else { prepareAuthToken(restClient, version, authToken); T restResponse = request.fire(); result = RestCallResult.SUCCESS; if (response != null) { response.onResponse(restResponse); } } } else if (bundle.containsKey(AccountManager.KEY_INTENT)) { Intent accountAuthenticatorResponse = bundle.getParcelable(AccountManager.KEY_INTENT); Intent editConnectionIntent = new Intent(Broadcasts.NO_CONNECTION_SPECIFIED); editConnectionIntent.putExtra(AccountManager.KEY_INTENT, accountAuthenticatorResponse); context.sendBroadcast(editConnectionIntent); result = RestCallResult.CONNECTION_ERROR; } } catch (ResourceAccessException | AuthenticatorException e) { messageHelper.showError(ErrorType.REST_MINOR, e); result = RestCallResult.CONNECTION_ERROR; } catch (HttpClientErrorException e) { String msg = e.getMessage(); switch (e.getStatusCode()) { case UNAUTHORIZED: // ok, session id is not valid anymore - invalidate it accountPropertiesManager.setAuthToken(null); result = RestCallResult.AUTH_ERROR; break; case NOT_FOUND: messageHelper.showError( ErrorType.REST_MAJOR, context.getString(R.string.rest_url_missing, msg, restClient.getRootUrl())); break; default: messageHelper.showError(ErrorType.REST_MAJOR, messageHelper.createMessage(e)); break; } } catch (Exception e) { messageHelper.showError(ErrorType.REST_MAJOR, e); } if (result == RestCallResult.SUCCESS) { messageHelper.resetMinorErrors(); } return result; }
public static <U> void outputBoxes(java.util.List<Box<U>> boxes) { int counter = 0; for (Box<U> box : boxes) { U boxContents = box.get(); System.out.println("Box # " + counter + " contains [" + boxContents.toString() + "]"); counter++; } }
public void generate(final U profile) { if (defaultRoles != null) { profile.addRoles(defaultRoles); } if (defaultPermissions != null) { profile.addPermissions(defaultPermissions); } }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { originatingTxId.writeExternal(out); U.writeUuid(out, originatingNodeId); U.writeCollection(out, recoveryWrites); }
public String toString() { BigInteger a = BigInteger.valueOf((int) numerator.doubleValue()); BigInteger b = BigInteger.valueOf((int) denominator.doubleValue()); double gcd = a.gcd(b).intValue(); return String.format( "%.2f / %.2f", numerator.doubleValue() / gcd, denominator.doubleValue() / gcd); }
@Override public boolean equals(Object obj) { if (!(obj instanceof HashableWeakReference)) return false; U referent = super.get(); @SuppressWarnings("unchecked") Object other = ((HashableWeakReference<?>) obj).get(); if (referent == null) return other == null; return referent.equals(other); }
/** * Processes unlock request. * * @param nodeId Sender node ID. * @param req Unlock request. */ @SuppressWarnings({"unchecked"}) private void processUnlockRequest(UUID nodeId, GridDistributedUnlockRequest req) { assert nodeId != null; try { ClassLoader ldr = ctx.deploy().globalLoader(); List<byte[]> keys = req.keyBytes(); for (byte[] keyBytes : keys) { K key = (K) U.unmarshal(ctx.marshaller(), new ByteArrayInputStream(keyBytes), ldr); while (true) { boolean created = false; GridDistributedCacheEntry<K, V> entry = peekexx(key); if (entry == null) { entry = entryexx(key); created = true; } try { entry.doneRemote( req.version(), req.version(), req.committedVersions(), req.rolledbackVersions()); // Note that we don't reorder completed versions here, // as there is no point to reorder relative to the version // we are about to remove. if (entry.removeLock(req.version())) { if (log.isDebugEnabled()) log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']'); if (created && entry.markObsolete(req.version())) removeIfObsolete(entry.key()); } else if (log.isDebugEnabled()) log.debug( "Received unlock request for unknown candidate " + "(added to cancelled locks set): " + req); break; } catch (GridCacheEntryRemovedException ignored) { if (log.isDebugEnabled()) log.debug( "Received remove lock request for removed entry (will retry) [entry=" + entry + ", req=" + req + ']'); } } } } catch (GridException e) { U.error(log, "Failed to unmarshal unlock key (unlock will not be performed): " + req, e); } }
/** @see java.lang.Object#equals(java.lang.Object) */ @SuppressWarnings("unchecked") public boolean equals(Object msg) { if (msg == null) return false; COSTmsg<Val, U> msgCast = (COSTmsg<Val, U>) msg; return sender.equals(msgCast.sender) && receiver.equals(msgCast.receiver) && context.equals(msgCast.context) && lb.equals(msgCast.lb) && ub.equals(msgCast.ub); }
public GenericFraction<Double, Double> add( GenericFraction<? extends Number, ? extends Number> gf) throws ZeroDenominatorException { double d = denominator.doubleValue() * gf.denominator.doubleValue(); double n = numerator.doubleValue() * (d / denominator.doubleValue()) + gf.numerator.doubleValue() * (d / gf.denominator.doubleValue()); return new GenericFraction<Double, Double>(n, d); }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { originatingTxId = new GridCacheVersion(); originatingTxId.readExternal(in); originatingNodeId = U.readUuid(in); recoveryWrites = U.readCollection(in); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, jobName); U.writeString(out, user); out.writeBoolean(hasCombiner); out.writeInt(numReduces); U.writeStringMap(out, props); }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { jobName = U.readString(in); user = U.readString(in); hasCombiner = in.readBoolean(); numReduces = in.readInt(); props = U.readStringMap(in); }
/** Checks users email and password by finding matching user. */ public final U findUser(String username, String rawPassword) { U userAuth = findUserAuthByUsername(username); if (userAuth == null) { return null; } if (!passwordEncoder.isPasswordValid(userAuth.getHashedPassword(), rawPassword)) { return null; } return userAuth; }
/** * リストの一部を切り出します。 * * @param i_from -1の場合0からです。 * @param i_until -1の場合最後までです。 * @return */ @Override public <U extends AscList<T>> U slice(int i_from, int i_until) { U ret = this.newInstance(); int from = i_from < 0 ? 0 : i_from; int until = i_until < 0 ? this._list.size() : i_until; for (int i = from; i < until; i++) { ret.add(this.get(i)); } return ret; }
@Override public void onNext(T t) { synchronized (this) { U b = buffer; if (b == null) { return; } b.add(t); } }
@Override public void beanChangePerformed(BeanEvent<U> evt) { U bean = evt.getBean(); if (!bean.getStatus().isRequest()) return; WeakReference<IConsumerProcess<U>> ref = processes.get(bean.getUniqueId()); try { if (ref == null) { // Might be in submit queue still updateQueue(bean); } else { IConsumerProcess<U> process = ref.get(); if (process != null) { process.getBean().setStatus(bean.getStatus()); process.getBean().setMessage(bean.getMessage()); if (bean.getStatus() == Status.REQUEST_TERMINATE) { processes.remove(bean.getUniqueId()); if (process.isPaused()) process.resume(); process.terminate(); } else if (bean.getStatus() == Status.REQUEST_PAUSE) { process.pause(); } else if (bean.getStatus() == Status.REQUEST_RESUME) { process.resume(); } } } } catch (EventException ne) { logger.error("Internal error, please contact your support representative.", ne); } }
@Override public <R, U extends PortalURL<R, U>> U newURL( ResourceType<R, U> resourceType, URLFactory urlFactory) { PortalURLContext urlContext = new PortalURLContext(controllerContext, siteKey); U url = urlFactory.newURL(resourceType, urlContext); if (url != null) { url.setAjax(false); url.setLocale(requestLocale); } return url; }