Search in sources :

Example 16 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project pulsar by yahoo.

the class ManagedCursorImpl method recoverFromLedger.

protected void recoverFromLedger(final ManagedCursorInfo info, final VoidCallback callback) {
    // Read the acknowledged position from the metadata ledger, then create
    // a new ledger and write the position into it
    ledger.mbean.startCursorLedgerOpenOp();
    long ledgerId = info.getCursorsLedgerId();
    bookkeeper.asyncOpenLedger(ledgerId, config.getDigestType(), config.getPassword(), (rc, lh, ctx) -> {
        if (log.isDebugEnabled()) {
            log.debug("[{}] Opened ledger {} for consumer {}. rc={}", ledger.getName(), ledgerId, name, rc);
        }
        if (isBkErrorNotRecoverable(rc)) {
            log.error("[{}] Error opening metadata ledger {} for consumer {}: {}", ledger.getName(), ledgerId, name, BKException.getMessage(rc));
            // Rewind to oldest entry available
            initialize(getRollbackPosition(info), callback);
            return;
        } else if (rc != BKException.Code.OK) {
            log.warn("[{}] Error opening metadata ledger {} for consumer {}: {}", ledger.getName(), ledgerId, name, BKException.getMessage(rc));
            callback.operationFailed(new ManagedLedgerException(BKException.getMessage(rc)));
            return;
        }
        // Read the last entry in the ledger
        cursorLedger = lh;
        lh.asyncReadLastEntry((rc1, lh1, seq, ctx1) -> {
            if (log.isDebugEnabled()) {
                log.debug("readComplete rc={} entryId={}", rc1, lh1.getLastAddConfirmed());
            }
            if (isBkErrorNotRecoverable(rc1)) {
                log.error("[{}] Error reading from metadata ledger {} for consumer {}: {}", ledger.getName(), ledgerId, name, BKException.getMessage(rc1));
                // Rewind to oldest entry available
                initialize(getRollbackPosition(info), callback);
                return;
            } else if (rc1 != BKException.Code.OK) {
                log.warn("[{}] Error reading from metadata ledger {} for consumer {}: {}", ledger.getName(), ledgerId, name, BKException.getMessage(rc1));
                callback.operationFailed(new ManagedLedgerException(BKException.getMessage(rc1)));
                return;
            }
            LedgerEntry entry = seq.nextElement();
            PositionInfo positionInfo;
            try {
                positionInfo = PositionInfo.parseFrom(entry.getEntry());
            } catch (InvalidProtocolBufferException e) {
                callback.operationFailed(new ManagedLedgerException(e));
                return;
            }
            PositionImpl position = new PositionImpl(positionInfo);
            if (positionInfo.getIndividualDeletedMessagesCount() > 0) {
                recoverIndividualDeletedMessages(positionInfo.getIndividualDeletedMessagesList());
            }
            recoveredCursor(position);
            callback.operationComplete();
        }, null);
    }, null);
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PositionInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.PositionInfo)

Example 17 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project pulsar by yahoo.

the class MetaStoreImplZookeeper method asyncGetCursorInfo.

@Override
public void asyncGetCursorInfo(String ledgerName, String consumerName, final MetaStoreCallback<ManagedCursorInfo> callback) {
    String path = prefix + ledgerName + "/" + consumerName;
    if (log.isDebugEnabled()) {
        log.debug("Reading from {}", path);
    }
    zk.getData(path, false, (rc, path1, ctx, data, stat) -> executor.submit(safeRun(() -> {
        if (rc != Code.OK.intValue()) {
            callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
        } else {
            try {
                ManagedCursorInfo info = parseManagedCursorInfo(data);
                callback.operationComplete(info, new ZKStat(stat));
            } catch (ParseException | InvalidProtocolBufferException e) {
                callback.operationFailed(new MetaStoreException(e));
            }
        }
    })), null);
    if (log.isDebugEnabled()) {
        log.debug("Reading from {} ok", path);
    }
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ParseException(com.google.protobuf.TextFormat.ParseException)

Example 18 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project pulsar by yahoo.

the class MetaStoreImplZookeeper method getManagedLedgerInfo.

@Override
public void getManagedLedgerInfo(final String ledgerName, final MetaStoreCallback<ManagedLedgerInfo> callback) {
    // Try to get the content or create an empty node
    zk.getData(prefix + ledgerName, false, (rc, path, ctx, readData, stat) -> executor.submit(safeRun(() -> {
        if (rc == Code.OK.intValue()) {
            try {
                ManagedLedgerInfo info = parseManagedLedgerInfo(readData);
                info = updateMLInfoTimestamp(info);
                callback.operationComplete(info, new ZKStat(stat));
            } catch (ParseException | InvalidProtocolBufferException e) {
                callback.operationFailed(new MetaStoreException(e));
            }
        } else if (rc == Code.NONODE.intValue()) {
            log.info("Creating '{}{}'", prefix, ledgerName);
            StringCallback createcb = (rc1, path1, ctx1, name) -> {
                if (rc1 == Code.OK.intValue()) {
                    ManagedLedgerInfo info = ManagedLedgerInfo.getDefaultInstance();
                    callback.operationComplete(info, new ZKStat());
                } else {
                    callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc1))));
                }
            };
            ZkUtils.asyncCreateFullPathOptimistic(zk, prefix + ledgerName, new byte[0], Acl, CreateMode.PERSISTENT, createcb, null);
        } else {
            callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
        }
    })), null);
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StringCallback(org.apache.zookeeper.AsyncCallback.StringCallback) ParseException(com.google.protobuf.TextFormat.ParseException) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)

Example 19 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method initialize.

private void initialize() throws RequestFailedException {
    if (getRequestHandler() != null) {
        getRequestHandler().exit();
    }
    requestHandler = new RequestHandler(this, client);
    getRequestHandler().sendServerRequests(ServerRequestEnvelope.create());
    playerProfile.updateProfile();
    ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
    getRequestHandler().sendServerRequests(downloadConfigRequest, true, RequestType.GET_BUDDY_WALKED, RequestType.GET_INCENSE_POKEMON);
    getAssetDigest();
    try {
        ByteString configVersionData = downloadConfigRequest.getData();
        if (PokemonMeta.checkVersion(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
            DownloadItemTemplatesMessage message = CommonRequests.getDownloadItemTemplatesRequest();
            ServerRequest request = new ServerRequest(RequestType.DOWNLOAD_ITEM_TEMPLATES, message);
            PokemonMeta.update(getRequestHandler().sendServerRequests(request, true), true);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    playerProfile.getProfile();
    try {
        LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getLevel()).build();
        ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons();
        ServerRequest request = envelope.add(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
        getRequestHandler().sendServerRequests(envelope);
        LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
        if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
            inventories.getItemBag().addAwardedItems(levelUpRewardsResponse);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    List<LoginListener> loginListeners = getListeners(LoginListener.class);
    for (LoginListener listener : loginListeners) {
        listener.onLogin(this);
    }
    loggingIn = false;
    active = true;
    // From now one we will start to check our accounts is ready to fire requests.
    // Actually, we can receive valid responses even with this first check,
    // that mark the tutorial state into LEGAL_SCREEN.
    // Following, we are going to check if the account binded to this session
    // have an avatar, a nickname, and all the other things that are usually filled
    // on the official client BEFORE sending any requests such as the getMapObject etc.
    ArrayList<TutorialState> tutorialStates = playerProfile.getTutorialState().getTutorialStates();
    if (tutorialStates.isEmpty()) {
        playerProfile.activateAccount();
    }
    if (!tutorialStates.contains(TutorialState.AVATAR_SELECTION)) {
        playerProfile.setupAvatar();
    }
    heartbeat.start();
    if (!tutorialStates.contains(TutorialState.POKEMON_CAPTURE)) {
        playerProfile.encounterTutorialComplete();
    }
    int remainingCodenameClaims = getPlayerProfile().getPlayerData().getRemainingCodenameClaims();
    if (!tutorialStates.contains(TutorialState.NAME_SELECTION) && remainingCodenameClaims > 0) {
        playerProfile.claimCodeName();
    }
    if (!tutorialStates.contains(TutorialState.FIRST_TIME_EXPERIENCE_COMPLETE)) {
        playerProfile.firstTimeExperienceComplete();
    }
}
Also used : LevelUpRewardsMessage(POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) Point(com.pokegoapi.api.map.Point) ServerRequestEnvelope(com.pokegoapi.main.ServerRequestEnvelope) LoginListener(com.pokegoapi.api.listener.LoginListener) RequestHandler(com.pokegoapi.main.RequestHandler) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) DownloadItemTemplatesMessage(POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage) ServerRequest(com.pokegoapi.main.ServerRequest) LevelUpRewardsResponse(POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse) TutorialState(POGOProtos.Enums.TutorialStateOuterClass.TutorialState)

Example 20 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method checkChallenge.

/**
	 * Checks for a challenge / captcha
	 *
	 * @return the new challenge URL, if any
	 * @throws RequestFailedException if an exception occurred while sending requests
	 * @deprecated CHECK_CHALLENGE is sent as a common request, should not be needed
	 */
@Deprecated
public String checkChallenge() throws RequestFailedException {
    CheckChallengeMessage message = CheckChallengeMessage.newBuilder().build();
    try {
        ServerRequest request = new ServerRequest(RequestType.CHECK_CHALLENGE, message);
        ByteString responseData = getRequestHandler().sendServerRequests(request, false);
        CheckChallengeResponse response = CheckChallengeResponse.parseFrom(responseData);
        String newChallenge = response.getChallengeUrl();
        if (response.getShowChallenge() && newChallenge != null && newChallenge.length() > 0) {
            updateChallenge(newChallenge, true);
            return newChallenge;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return null;
}
Also used : CheckChallengeMessage(POGOProtos.Networking.Requests.Messages.CheckChallengeMessageOuterClass.CheckChallengeMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CheckChallengeResponse(POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse) ByteString(com.google.protobuf.ByteString) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)104 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)21 IOException (java.io.IOException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CodedInputStream (com.google.protobuf.CodedInputStream)4 List (java.util.List)4 TypicalData (protos.TypicalData)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 YamcsClient (org.yamcs.studio.core.client.YamcsClient)3 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2