Examples of SlobId


Examples of com.google.walkaround.slob.shared.SlobId

      final List<ChangeData<String>> initialHistory) throws IOException {
    try {
      return new RetryHelper().run(
          new RetryHelper.Body<SlobId>() {
            @Override public SlobId run() throws RetryableFailure, PermanentFailure {
              SlobId udwId = getRandomObjectId();
              CheckedTransaction tx = datastore.beginTransaction();
              try {
                udwStore.newObject(tx, udwId, metadata, initialHistory, false);
                tx.commit();
              } catch (SlobAlreadyExistsException e) {
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

    String[] tokens = splitTokens(waveletId.getId());
    Preconditions.checkArgument(tokens.length == 2,
        "Wavelet id does not consist of two tokens: %s", waveletId);
    if (IdConstants.CONVERSATION_WAVELET_PREFIX.equals(tokens[0])
        || IdConstants.USER_DATA_WAVELET_PREFIX.equals(tokens[0])) {
      return new SlobId(tokens[1]);
    } else {
      throw new RuntimeException("Unknown prefix in wavelet id: " + waveletId);
    }
  }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

    xsrfHelper.verify(makeAction(signedSession.getSession()), signedSession.getSignature());
    return objectSessionFromProto(signedSession.getSession());
  }

  public static ObjectSession objectSessionFromProto(ObjectSessionProto proto) {
    return new ObjectSession(new SlobId(proto.getObjectId()),
        new ClientId(proto.getClientId()),
        proto.getStoreType());
  }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

      // TODO(ohler): This should be getOrCreateAndConnect(), so that we can avoid
      // reconstructing the state of the wavelet that we just created.  But
      // snapshot caching would help with this as well, so we should probably do
      // that first.
      SlobId udwId = waveletCreator.getOrCreateUdw(convObjectId);
      Pair<ConnectResult, String> udwPair;
      try {
        udwPair = udwStore.connect(udwId, clientId);
      } catch (SlobNotFoundException e) {
        throw new RuntimeException("UDW disappeared right after getOrCreateUdw(): " + udwId);
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

    @Override protected void populateEntity(WaveletMapping mapping, Entity out) {
    }

    @Override protected WaveletMapping parse(Entity e) throws InvalidPropertyException {
      return new WaveletMapping(new SlobId(e.getKey().getName()));
    }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

        useUdw = false;
        udwData = null;
      } else {
        useUdw = true;
        udwData = vars.getUdw();
        udwObjectId = new SlobId(vars.getUdw().getConnectResponse()
            .getSignedSession().getSession().getObjectId());
      }
      VersionChecker versionChecker = new VersionChecker(rpc, vars.getClientVersion());
      // NOTE(danilatos): Use the highest priority timer, since we can't afford to
      // let it be starved due to some bug with another non-terminating
      // high-priority task. This task runs infrequently and is very minimal so
      // the risk of impacting the UI is low.
      SchedulerInstance.getHighPriorityTimer().scheduleRepeating(versionChecker,
          VERSION_CHECK_INTERVAL_MS, VERSION_CHECK_INTERVAL_MS);
    }
    final RandomProviderImpl random =
        // TODO(ohler): Get a stronger RandomProvider.
        RandomProviderImpl.ofSeed(randomSeed);
    final RandomBase64Generator random64 = new RandomBase64Generator(new RandomProvider() {
      @Override public int nextInt(int upperBound) {
        return random.nextInt(upperBound);
      }});
    final ParticipantId userId;
    try {
      userId = ParticipantId.of(userIdString);
    } catch (InvalidParticipantAddress e1) {
      Window.alert("Invalid user id received from server: " + userIdString);
      return;
    }
    convObjectId = new SlobId(convObjectIdString);

    idGenerator = new IdHack.MinimalIdGenerator(
        IdHack.convWaveletIdFromObjectId(convObjectId),
        useUdw ? IdHack.udwWaveletIdFromObjectId(udwObjectId)
        // Some code depends on this not to return null, so let's return
        // something.
        : IdHack.DISABLED_UDW_ID,
        random64);

    // TODO(ohler): Make the server's response to the contacts RPC indicate
    // whether an OAuth token is needed, and enable the button dynamically when
    // appropriate, rather than statically.
    UIObject.setVisible(Document.get().getElementById("enableAvatarsButton"),
        !haveOAuthToken);
    @Nullable final LoadWaveService loadWaveService = isLive ? new LoadWaveService(rpc) : null;
    @Nullable final ChannelConnectService channelService =
        isLive ? new ChannelConnectService(rpc) : null;

    new Stages() {
      @Override
      protected AsyncHolder<StageZero> createStageZeroLoader() {
        return new StageZero.DefaultProvider() {
          @Override
          protected UncaughtExceptionHandler createUncaughtExceptionHandler() {
            return WalkaroundUncaughtExceptionHandler.INSTANCE;
          }
        };
      }

      @Override
      protected AsyncHolder<StageOne> createStageOneLoader(StageZero zero) {
        return new StageOne.DefaultProvider(zero) {
          protected final ParticipantViewImpl.Helper<ParticipantAvatarDomImpl> participantHelper =
              new ParticipantViewImpl.Helper<ParticipantAvatarDomImpl>() {
                @Override public void remove(ParticipantAvatarDomImpl impl) {
                  impl.remove();
                }
                @Override public ProfilePopupView showParticipation(ParticipantAvatarDomImpl impl) {
                  return new ProfilePopupWidget(impl.getElement(),
                      AlignedPopupPositioner.BELOW_RIGHT);
                }
              };

          @Override protected UpgradeableDomAsViewProvider createViewProvider() {
            return new FullStructure(createCssProvider()) {
              @Override public ParticipantView asParticipant(Element e) {
                return e == null ? null : new ParticipantViewImpl<ParticipantAvatarDomImpl>(
                    participantHelper, ParticipantAvatarDomImpl.of(e));
              }
            };
          }
        };
      }

      @Override
      protected AsyncHolder<StageTwo> createStageTwoLoader(final StageOne one) {
        return new StageTwo.DefaultProvider(one, null) {
          WaveViewData waveData;
          StringMap<DocOp> diffMap = CollectionUtils.createStringMap();

          @Override protected DomRenderer createRenderer() {
            final BlipQueueRenderer pager = getBlipQueue();
            DocRefRenderer docRenderer = new DocRefRenderer() {
                @Override
                public UiBuilder render(
                    ConversationBlip blip, IdentityMap<ConversationThread, UiBuilder> replies) {
                  // Documents are rendered blank, and filled in later when
                  // they get paged in.
                  pager.add(blip);
                  return DocRefRenderer.EMPTY.render(blip, replies);
                }
              };
            RenderingRules<UiBuilder> rules = new MyFullDomRenderer(
                getBlipDetailer(), docRenderer, getProfileManager(),
                getViewIdMapper(), createViewFactories(), getThreadReadStateMonitor()) {
              @Override
              public UiBuilder render(Conversation conversation, ParticipantId participant) {
                // Same as super class, but using avatars instead of names.
                Profile profile = getProfileManager().getProfile(participant);
                String id = getViewIdMapper().participantOf(conversation, participant);
                ParticipantAvatarViewBuilder participantUi =
                    ParticipantAvatarViewBuilder.create(id);
                participantUi.setAvatar(profile.getImageUrl());
                participantUi.setName(profile.getFullName());
                return participantUi;
              }
            };
            return new HtmlDomRenderer(ReductionBasedRenderer.of(rules, getConversations()));
          }

          @Override
          protected ProfileManager createProfileManager() {
            return ContactsManager.create(rpc);
          }

          @Override
          protected void create(final Accessor<StageTwo> whenReady) {
            super.create(whenReady);
          }

          @Override
          protected IdGenerator createIdGenerator() {
            return idGenerator;
          }

          @Override
          protected void fetchWave(final Accessor<WaveViewData> whenReady) {
            wavelets.updateData(
                parseConvWaveletData(
                    convConnectResponse, convSnapshot,
                    getDocumentRegistry(), diffMap));
            if (useUdw) {
              wavelets.updateData(
                  parseUdwData(
                      udwData.getConnectResponse(),
                      udwData.getSnapshot(),
                      getDocumentRegistry()));
            }
            Document.get().getElementById(WAVEPANEL_PLACEHOLDER).setInnerText("");
            waveData = createWaveViewData();
            whenReady.use(waveData);
          }

          @Override
          protected WaveDocuments<LazyContentDocument> createDocumentRegistry() {
            IndexedDocumentImpl.performValidation = false;

            DocumentFactory<?> dataDocFactory =
                ObservablePluggableMutableDocument.createFactory(createSchemas());
            DocumentFactory<LazyContentDocument> blipDocFactory =
                new DocumentFactory<LazyContentDocument>() {
                  private final Registries registries = RegistriesHolder.get();

                  @Override
                  public LazyContentDocument create(
                      WaveletId waveletId, String docId, DocInitialization content) {
                    SimpleDiffDoc diff = SimpleDiffDoc.create(content, diffMap.get(docId));
                    return LazyContentDocument.create(registries, diff);
                  }
                };

            return WaveDocuments.create(blipDocFactory, dataDocFactory);
          }

          @Override
          protected ParticipantId createSignedInUser() {
            return userId;
          }

          @Override
          protected String createSessionId() {
            // TODO(ohler): Write a note here about what this is and how it
            // interacts with walkaround's session management.
            return random64.next(6);
          }

          @Override
          protected MuxConnector createConnector() {
            return new MuxConnector() {
              private void connectWavelet(StaticChannelBinder binder,
                  ObservableWaveletData wavelet) {
                WaveletId waveletId = wavelet.getWaveletId();
                SlobId objectId = IdHack.objectIdFromWaveletId(waveletId);
                WaveletEntry data = wavelets.get(objectId);
                Assert.check(data != null, "Unknown wavelet: %s", waveletId);
                if (data.getChannelToken() == null) {
                  // TODO(danilatos): Handle with a nicer message, and maybe try to
                  // reconnect later.
                  Window.alert("Could not open a live connection to this wave. "
                      + "It will be read-only, changes will not be saved!");
                  return;
                }

                String debugSuffix;
                if (objectId.equals(convObjectId)) {
                  debugSuffix = "-c";
                } else if (objectId.equals(udwObjectId)) {
                  debugSuffix = "-u";
                } else {
                  debugSuffix = "-xxx";
                }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

    protected void populateEntity(ConvUdwMapping entry, Entity out) {
      DatastoreUtil.setNonNullIndexedProperty(out, UDW_ID_PROPERTY, entry.getUdwId().getId());
    }

    private SlobId parseObjectId(Entity e, String propertyName, String objectIdStr) {
      return new SlobId(objectIdStr);
    }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

      String key = e.getKey().getName();
      int space = key.indexOf(' ');
      if (space == -1 || space != key.lastIndexOf(' ')) {
        throw new InvalidPropertyException(e, "key");
      }
      SlobId convObjectId = parseObjectId(e, "key", key.substring(0, space));
      StableUserId userId = new StableUserId(key.substring(space + 1));
      SlobId udwId = parseObjectId(e, UDW_ID_PROPERTY,
          DatastoreUtil.getExistingProperty(e, UDW_ID_PROPERTY, String.class));
      return new ConvUdwMapping(new Key(convObjectId, userId), udwId);
    }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

    log.info(this + ": doPost()");
    if (req.getHeader("X-AppEngine-QueueName") == null) {
      throw new BadRequestException();
    }
    String storeType = requireParameter(req, STORE_TYPE_PARAM);
    SlobId slobId = new SlobId(requireParameter(req, SLOB_ID_PARAM));
    storeSelector.get(storeType).getPostCommitActionScheduler().taskInvoked(slobId);
  }
View Full Code Here

Examples of com.google.walkaround.slob.shared.SlobId

                @Nullable RemoteConvWavelet entry =
                    perUserTable.getWavelet(tx, userId, instance, waveletName);
                if (isPrivate) {
                  if (entry != null && entry.getPrivateLocalId() != null
                      && !(task.hasExistingSlobIdToIgnore()
                          && new SlobId(task.getExistingSlobIdToIgnore()).equals(
                              entry.getPrivateLocalId()))) {
                    log.info("Private import already exists, aborting: " + entry);
                    return true;
                  } else {
                    return false;
                  }
                } else {
                  if (entry != null && entry.getSharedLocalId() != null
                      && !(task.hasExistingSlobIdToIgnore()
                          && new SlobId(task.getExistingSlobIdToIgnore()).equals(
                              entry.getSharedLocalId()))) {
                    log.info("Shared import already exists, aborting: " + entry);
                    return true;
                  } else {
                    return false;
                  }
                }
              } finally {
                tx.close();
              }
            }
          });
      if (alreadyImportedForThisUser) {
        throw TaskCompleted.noFollowup();
      }
      if (!isPrivate) {
        @Nullable SlobId existingSharedImport =
              sharedImportTable.lookupWithoutTx(instance, waveletName);
        if (existingSharedImport != null
            && !(task.hasExistingSlobIdToIgnore()
                && new SlobId(task.getExistingSlobIdToIgnore()).equals(existingSharedImport))) {
          log.info("Found existing shared import " + existingSharedImport + ", re-using");
          ensureParticipant(existingSharedImport);
          addToPerUserTableWithoutTx(existingSharedImport, isPrivate);
          throw TaskCompleted.noFollowup();
        }
      }
      Map<String, AttachmentId> attachmentMapping = getAttachmentsAndMapping(snapshot);
      List<WaveletOperation> participantFixup = Lists.newArrayList();
      if (isPrivate) {
        for (String participant : ImmutableList.copyOf(wavelet.getParticipantList())) {
          participantFixup.add(
              HistorySynthesizer.newRemoveParticipant(importingUser.getAddress(),
                  wavelet.getLastModifiedTimeMillis(), participant));
        }
        participantFixup.add(
            HistorySynthesizer.newAddParticipant(importingUser.getAddress(),
                wavelet.getLastModifiedTimeMillis(), importingUser.getAddress()));
      } else {
        if (!wavelet.getParticipantList().contains(importingUser.getAddress())) {
          log.info(
              importingUser + " is not a participant, adding: " + wavelet.getParticipantList());
          participantFixup.add(
              HistorySynthesizer.newAddParticipant(importingUser.getAddress(),
                  wavelet.getLastModifiedTimeMillis(), importingUser.getAddress()));
        }
      }
      log.info("participantFixup=" + participantFixup);
      boolean preserveHistory = !task.getSettings().getSynthesizeHistory();
      log.info("preserveHistory=" + preserveHistory);
      ImportMetadata importMetadata = new ImportMetadataGsonImpl();
      importMetadata.setImportBeginTimeMillis(System.currentTimeMillis());
      importMetadata.setImportFinished(false);
      importMetadata.setOriginalImporter(userId.getId());
      importMetadata.setSourceInstance(instance.serialize());
      importMetadata.setRemoteWaveId(waveletName.waveId.serialise());
      importMetadata.setRemoteWaveletId(waveletName.waveletId.serialise());
      importMetadata.setRemoteHistoryCopied(preserveHistory);
      importMetadata.setRemoteVersionImported(snapshot.getFirst().getVersion());
      ConvMetadataGsonImpl convMetadata = new ConvMetadataGsonImpl();
      convMetadata.setImportMetadata(importMetadata);
      final SlobId newId;
      if (!preserveHistory) {
        List<WaveletOperation> history = Lists.newArrayList();
        WaveletHistoryConverter converter = new WaveletHistoryConverter(
            getConvNindoConverter(attachmentMapping));
        for (WaveletOperation op :
            new HistorySynthesizer().synthesizeHistory(wavelet, snapshot.getSecond())) {
          history.add(converter.convertAndApply(convertGooglewaveToGmail(op)));
        }
        history.addAll(participantFixup);
        newId = waveletCreator.newConvWithGeneratedId(
            ImmutableList.<WaveletOperation>of(), convMetadata, true);
        ConvHistoryWriter historyWriter = new ConvHistoryWriter(newId);
        try {
          for (WaveletOperation op : history) {
            historyWriter.append(op);
          }
          historyWriter.finish();
        } catch (ChangeRejected e) {
          log.warning("Synthesized history rejected: " + history);
          throw new RuntimeException("Synthesized history rejected", e);
        }
      } else {
        long version = 0;
        newId = waveletCreator.newConvWithGeneratedId(
            ImmutableList.<WaveletOperation>of(), convMetadata, true);
        ConvHistoryWriter historyWriter = new ConvHistoryWriter(newId);
        WaveletHistoryConverter converter =
            new WaveletHistoryConverter(getConvNindoConverter(attachmentMapping));
        try {
          // NOTE(ohler): We have to stop at snapshot.getFirst().getVersion() even if
          // getRawDeltas gives us more, since otherwise, participantFixup may be out-of-date.
          while (version < snapshot.getFirst().getVersion()) {
            log.info("converter state: " + converter);
            List<ProtocolAppliedWaveletDelta> rawDeltas =
                robotApi.getRawDeltas(waveletName, version);
            for (ProtocolAppliedWaveletDelta rawDelta : rawDeltas) {
              WaveletDelta delta = CoreWaveletOperationSerializer.deserialize(
                  ProtocolWaveletDelta.parseFrom(rawDelta.getSignedOriginalDelta().getDelta()));
              for (WaveletOperation badOp : delta) {
                Preconditions.checkState(badOp.getContext().getTimestamp() == -1,
                    "Unexpected timestamp: %s in delta %s", badOp, delta);
                // TODO(ohler): Rename
                // CoreWaveletOperationSerializer.deserialize() to
                // deserializeWithNoTimestamp() or something.
                WaveletOperation withTimestamp = WaveletOperation.cloneOp(badOp,
                    new WaveletOperationContext(badOp.getContext().getCreator(),
                        rawDelta.getApplicationTimestamp(),
                        badOp.getContext().getVersionIncrement()));
                WaveletOperation converted =
                    converter.convertAndApply(convertGooglewaveToGmail(withTimestamp));
                //log.info(version + ": " + op + " -> " + converted);
                historyWriter.append(converted);
                version++;
              }
            }
          }
          historyWriter.append(participantFixup);
          historyWriter.finish();
        } catch (ChangeRejected e) {
          log.log(Level.SEVERE, "Change rejected somewhere at or before version " + version
              + ", re-importing without history", e);
          ImportSettings settings = task.getSettings();
          settings.setSynthesizeHistory(true);
          task.setSettings(settings);
          throw TaskCompleted.withFollowup(task);
        }
      }
      log.info("Imported wavelet " + waveletName + " as local id " + newId);
      boolean abandonAndRetry = new RetryHelper().run(
          new RetryHelper.Body<Boolean>() {
            @Override public Boolean run() throws RetryableFailure, PermanentFailure {
              CheckedTransaction tx = datastore.beginTransactionXG();
              try {
                if (!isPrivate) {
                  @Nullable SlobId existingSharedImport =
                      sharedImportTable.lookup(tx, instance, waveletName);
                  if (existingSharedImport != null
                      && !(task.hasExistingSlobIdToIgnore()
                          && new SlobId(task.getExistingSlobIdToIgnore()).equals(
                              existingSharedImport))) {
                    log.warning("Found existing shared import " + existingSharedImport
                        + ", abandoning import and retrying");
                    return true;
                  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.