All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.contek.invoker.bybit.api.websocket.WebSocketApi Maven / Gradle / Ivy

The newest version!
package io.contek.invoker.bybit.api.websocket;

import com.google.common.collect.ImmutableList;
import io.contek.invoker.commons.actor.IActor;
import io.contek.invoker.commons.actor.ratelimit.TypedPermitRequest;
import io.contek.invoker.commons.websocket.*;
import io.contek.invoker.security.ICredential;

import javax.annotation.concurrent.ThreadSafe;

@ThreadSafe
public abstract class WebSocketApi extends BaseWebSocketApi {

  private final WebSocketContext context;
  private final WebSocketRequestIdGenerator requestIdGenerator;

  protected WebSocketApi(IActor actor, WebSocketContext context) {
    this(actor, context, new WebSocketMessageParser());
  }

  private WebSocketApi(IActor actor, WebSocketContext context, WebSocketMessageParser parser) {
    this(actor, context, parser, new WebSocketRequestIdGenerator());
  }

  private WebSocketApi(
      IActor actor,
      WebSocketContext context,
      WebSocketMessageParser parser,
      WebSocketRequestIdGenerator requestIdGenerator) {
    super(
        actor,
        parser,
        new WebSocketAuthenticator(actor.getCredential(), requestIdGenerator, actor.getClock()),
        IWebSocketLiveKeeper.noOp());
    this.context = context;
    this.requestIdGenerator = requestIdGenerator;
  }

  public WebSocketRequestIdGenerator getRequestIdGenerator() {
    return requestIdGenerator;
  }

  @Override
  protected final ImmutableList getRequiredQuotas() {
    return ImmutableList.of();
  }

  @Override
  protected final WebSocketCall createCall(ICredential credential) {
    return WebSocketCall.fromUrl(context.getBaseUrl() + getUrlSuffix());
  }

  @Override
  protected final void checkErrorMessage(AnyWebSocketMessage message)
      throws WebSocketRuntimeException {}

  protected abstract String getUrlSuffix();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy