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

org.infinispan.server.resp.commands.connection.SELECT Maven / Gradle / Ivy

There is a newer version: 15.1.4.Final
Show newest version
package org.infinispan.server.resp.commands.connection;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CompletionStage;

import org.infinispan.Cache;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.server.core.transport.ConnectionMetadata;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespErrorUtil;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;
import org.infinispan.server.resp.serialization.Resp3Response;

import io.netty.channel.ChannelHandlerContext;

/**
 * @link SELECT
 * @since 14.0
 */
public class SELECT extends RespCommand implements Resp3Command {
   public SELECT() {
      super(-1, 0, 0, 0);
   }

   @Override
   public CompletionStage perform(Resp3Handler handler,
                                                      ChannelHandlerContext ctx,
                                                      List arguments) {
      String db = new String(arguments.get(0), StandardCharsets.US_ASCII);
      try {
         Cache cache = handler.respServer().getCacheManager().getCache(db);
         ConnectionMetadata metadata = ConnectionMetadata.getInstance(ctx.channel());
         handler.setCache(cache.getAdvancedCache().withSubject(metadata.subject()).withMediaType(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_OCTET_STREAM));
         metadata.cache(cache.getName());
         Resp3Response.ok(handler.allocator());
      } catch (CacheException e) {
         RespErrorUtil.customError("DB index is out of range", handler.allocator());
      }
      return handler.myStage();
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy