private BucketId getBucketId(Message msg) {
            return switch (msg.getType()) {
                case DocumentProtocol.MESSAGE_PUTDOCUMENT ->
                        factory.getBucketId(((PutDocumentMessage) msg).getDocumentPut().getDocument().getId());
                case DocumentProtocol.MESSAGE_GETDOCUMENT ->
                        factory.getBucketId(((GetDocumentMessage) msg).getDocumentId());
                case DocumentProtocol.MESSAGE_REMOVEDOCUMENT ->
                        factory.getBucketId(((RemoveDocumentMessage) msg).getDocumentId());
                case DocumentProtocol.MESSAGE_UPDATEDOCUMENT ->
                        factory.getBucketId(((UpdateDocumentMessage) msg).getDocumentUpdate().getId());
                case DocumentProtocol.MESSAGE_GETBUCKETLIST -> ((GetBucketListMessage) msg).getBucketId();
                case DocumentProtocol.MESSAGE_STATBUCKET -> ((StatBucketMessage) msg).getBucketId();
                case DocumentProtocol.MESSAGE_CREATEVISITOR -> ((CreateVisitorMessage) msg).getBuckets().get(0);
                case DocumentProtocol.MESSAGE_REMOVELOCATION -> ((RemoveLocationMessage) msg).getBucketId();
                default -> {
                    log.log(Level.SEVERE, "Message type '" + msg.getType() + "' not supported.");
                    yield null;
                }
            };
        }
Helper class to get the bucket identifier of a message.
documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java