• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConsistencyLevel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.cassandra.thrift.ConsistencyLevel的典型用法代码示例。如果您正苦于以下问题:Java ConsistencyLevel类的具体用法?Java ConsistencyLevel怎么用?Java ConsistencyLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConsistencyLevel类属于org.apache.cassandra.thrift包,在下文中一共展示了ConsistencyLevel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: executeStatement

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
private CqlResult executeStatement(Client client, String statement) throws ThriftApiExecutionException
{
    ByteBuffer buf = ByteBufferUtil.bytes(statement);
    try
    {
        if (cqlVersion.charAt(0) >= '3')
        {
            return client.execute_cql3_query(buf, Compression.NONE, ConsistencyLevel.ONE);
        } else
        {
            return client.execute_cql_query(buf, Compression.NONE);
        }
    } catch (Exception e)
    {
        getLog().debug(statement);
        throw new ThriftApiExecutionException(e);
    }
}
 
开发者ID:mojohaus,项目名称:cassandra-maven-plugin,代码行数:19,代码来源:AbstractCqlExecMojo.java


示例2: get

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * get 讀取1個column
 *
 * @throws Exception
 */
@Test
public void get() throws Exception {
	String KEYSPACE = "mock";
	client.set_keyspace(KEYSPACE);

	// 讀取1個column
	String COLUMN_FAMILY = "student";
	ColumnPath columnPath = new ColumnPath(COLUMN_FAMILY);
	//
	String COLUMN = "grad";
	columnPath.setColumn(ByteBufferHelper.toByteBuffer(COLUMN));

	String ROW_KEY = "Jack";
	// key, column_path, consistency_level
	ColumnOrSuperColumn cos = client.get(
			ByteBufferHelper.toByteBuffer(ROW_KEY), columnPath,
			ConsistencyLevel.ONE);// NotFoundException

	Column column = cos.getColumn();
	System.out.println(ROW_KEY + ", "
			+ ByteHelper.toString(column.getName()) + ": "
			+ ByteHelper.toString(column.getValue()) + ", "
			+ column.getTimestamp());
	// Jack, grad: 5, 1380932164492000
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:31,代码来源:CassandraThriftDMLTest.java


示例3: SettingsCommand

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public SettingsCommand(Command type, Options options, Count count, Uncertainty uncertainty)
{
    this.type = type;
    this.tries = Math.max(1, Integer.parseInt(options.retries.value()) + 1);
    this.ignoreErrors = options.ignoreErrors.setByUser();
    this.consistencyLevel = ConsistencyLevel.valueOf(options.consistencyLevel.value().toUpperCase());
    if (count != null)
    {
        this.count = Long.parseLong(count.count.value());
        this.targetUncertainty = -1;
        this.minimumUncertaintyMeasurements = -1;
        this.maximumUncertaintyMeasurements = -1;
    }
    else
    {
        this.count = -1;
        this.targetUncertainty = Double.parseDouble(uncertainty.uncertainty.value());
        this.minimumUncertaintyMeasurements = Integer.parseInt(uncertainty.minMeasurements.value());
        this.maximumUncertaintyMeasurements = Integer.parseInt(uncertainty.maxMeasurements.value());
    }
}
 
开发者ID:mafernandez-stratio,项目名称:cassandra-cqlMod,代码行数:22,代码来源:SettingsCommand.java


示例4: getColumnValue

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);

    long timestamp = System.currentTimeMillis();
    ColumnPath cp = new ColumnPath(cf);
    ColumnParent par = new ColumnParent(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
开发者ID:wso2,项目名称:wso2-cassandra,代码行数:18,代码来源:ThriftColumnFamilyTest.java


示例5: SettingsCommand

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public SettingsCommand(Command type, Options options, Count count, Uncertainty uncertainty)
{
    this.type = type;
    this.tries = Math.max(1, Integer.parseInt(options.retries.value()) + 1);
    this.ignoreErrors = options.ignoreErrors.setByUser();
    this.consistencyLevel = ConsistencyLevel.valueOf(options.consistencyLevel.value().toUpperCase());
    this.keysAtOnce = Integer.parseInt(options.atOnce.value());
    this.add = options.add.get();
    if (count != null)
    {
        this.count = Long.parseLong(count.count.value());
        this.targetUncertainty = -1;
        this.minimumUncertaintyMeasurements = -1;
        this.maximumUncertaintyMeasurements = -1;
    }
    else
    {
        this.count = -1;
        this.targetUncertainty = Double.parseDouble(uncertainty.uncertainty.value());
        this.minimumUncertaintyMeasurements = Integer.parseInt(uncertainty.minMeasurements.value());
        this.maximumUncertaintyMeasurements = Integer.parseInt(uncertainty.maxMeasurements.value());
    }
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:24,代码来源:SettingsCommand.java


示例6: getRow

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
protected Map<String,Object> getRow(String tableName, String[] columnNameList, Object rowKey) {
    Connection connection = null;
    try {  
        connection = connectionPool.acquireConnection();
        String primaryKeyName = getTablePrimaryKeyName(tableName);
        String rowKeyString = rowKey.toString();
        List<Map<String,Object>> rowList = connection.getRowsByPrimaryKey(tableName,
                primaryKeyName, rowKeyString, rowKeyString, columnNameList, ConsistencyLevel.ONE);
        //if (rowList.size() != 1)
        //    throw new StorageException("Row not found: table = \"" + tableName + "\"; key = \"" + rowKeyString + "\"");
        if (rowList.size() == 0)
            return null;
        return rowList.get(0);
    }
    finally {
        if (connection != null)
            connectionPool.releaseConnection(connection);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:20,代码来源:CassandraStorageSource.java


示例7: ReadCallback

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Constructor when response count has to be calculated and blocked for.
 */
public ReadCallback(IResponseResolver<T> resolver, ConsistencyLevel consistencyLevel, IReadCommand command, List<InetAddress> endpoints)
{
    this.command = command;
    this.blockfor = determineBlockFor(consistencyLevel, command.getKeyspace());
    this.resolver = resolver;
    this.startTime = System.currentTimeMillis();
    boolean repair = randomlyReadRepair();
    this.endpoints = repair || resolver instanceof RowRepairResolver
                   ? endpoints
                   : preferredEndpoints(endpoints);

    if (logger.isDebugEnabled())
        logger.debug(String.format("Blockfor/repair is %s/%s; setting up requests to %s",
                                   blockfor, repair, StringUtils.join(this.endpoints, ",")));
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:19,代码来源:ReadCallback.java


示例8: determineBlockFor

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public int determineBlockFor(ConsistencyLevel consistencyLevel, String table)
{
    switch (consistencyLevel)
    {
        case ONE:
        case ANY:
            return 1;
        case TWO:
            return 2;
        case THREE:
            return 3;
        case QUORUM:
            return (Table.open(table).getReplicationStrategy().getReplicationFactor() / 2) + 1;
        case ALL:
            return Table.open(table).getReplicationStrategy().getReplicationFactor();
        default:
            throw new UnsupportedOperationException("invalid consistency level: " + consistencyLevel);
    }
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:20,代码来源:ReadCallback.java


示例9: performWrite

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Perform the write of a mutation given a WritePerformer.
 * Gather the list of write endpoints, apply locally and/or forward the mutation to
 * said write endpoint (deletaged to the actual WritePerformer) and wait for the
 * responses based on consistency level.
 *
 * @param mutation the mutation to be applied
 * @param consistency_level the consistency level for the write operation
 * @param performer the WritePerformer in charge of appliying the mutation
 * given the list of write endpoints (either standardWritePerformer for
 * standard writes or counterWritePerformer for counter writes).
 */
public static IWriteResponseHandler performWrite(IMutation mutation, ConsistencyLevel consistency_level, String localDataCenter, WritePerformer performer) throws UnavailableException, TimeoutException, IOException
{
    String table = mutation.getTable();
    AbstractReplicationStrategy rs = Table.open(table).getReplicationStrategy();

    Collection<InetAddress> writeEndpoints = getWriteEndpoints(table, mutation.key());
    Multimap<InetAddress, InetAddress> hintedEndpoints = rs.getHintedEndpoints(writeEndpoints);

    IWriteResponseHandler responseHandler = rs.getWriteResponseHandler(writeEndpoints, hintedEndpoints, consistency_level);

    // exit early if we can't fulfill the CL at this time
    responseHandler.assureSufficientLiveNodes();

    performer.apply(mutation, hintedEndpoints, responseHandler, localDataCenter, consistency_level);
    return responseHandler;
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:29,代码来源:StorageProxy.java


示例10: read

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Performs the actual reading of a row out of the StorageService, fetching
 * a specific set of column names from a given column family.
 */
public static List<Row> read(List<ReadCommand> commands, ConsistencyLevel consistency_level)
        throws IOException, UnavailableException, TimeoutException, InvalidRequestException
{
    if (StorageService.instance.isBootstrapMode())
        throw new UnavailableException();
    long startTime = System.nanoTime();
    List<Row> rows;
    try
    {
        rows = fetchRows(commands, consistency_level);
    }
    finally
    {
        readStats.addNano(System.nanoTime() - startTime);
    }
    return rows;
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:22,代码来源:StorageProxy.java


示例11: assureSufficientLiveNodes

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public void assureSufficientLiveNodes() throws UnavailableException
{
    if (consistencyLevel == ConsistencyLevel.ANY)
    {
        // ensure there are blockFor distinct living nodes (hints are ok).
        if (hintedEndpoints.keySet().size() < responses.get())
            throw new UnavailableException();
        return;
    }

    // count destinations that are part of the desired target set
    int liveNodes = 0;
    for (InetAddress destination : hintedEndpoints.keySet())
    {
        if (writeEndpoints.contains(destination))
            liveNodes++;
    }
    if (liveNodes < responses.get())
    {
        throw new UnavailableException();
    }
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:23,代码来源:WriteResponseHandler.java


示例12: QueryOneMinute

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public List<String> QueryOneMinute(String min) {
	List<String> userList = new ArrayList<String>();
	try {
		List<ColumnOrSuperColumn> results = client.get_slice(Utils
				.toByteBuffer(min), columnParent, predicate,
				ConsistencyLevel.ONE);
		for (ColumnOrSuperColumn cc : results) {
			SuperColumn superColumn = cc.getSuper_column();
			List<Column> list = superColumn.getColumns();
			for (Column c : list) {
				String columnName = new String(c.getName(), "UTF-8");
				if (columnName.equals("username")) {
					String value = new String(c.getValue(), "UTF-8");
					if (!userList.contains(value)) {
						userList.add(value);
					}
				}
			}
		}
	} catch (Exception e) {
		System.out.println(e);
	}
	return userList;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:25,代码来源:CasTimeReader.java


示例13: QueryOneMinute

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public List<String> QueryOneMinute(String min){
	List<String> bookList = new ArrayList<String>();
	try {
		List<ColumnOrSuperColumn> results = client.get_slice(Utils
				.toByteBuffer(min), columnParent, predicate,
				ConsistencyLevel.ONE);
		for (ColumnOrSuperColumn cc : results) {
			SuperColumn superColumn = cc.getSuper_column();
			List<Column> list = superColumn.getColumns();
			for (Column c : list) {
				String columnName = new String(c.getName(), "UTF-8");
				if (columnName.equals("bookno")) {
					String value = new String(c.getValue(), "UTF-8");
					if (!bookList.contains(value)) {
						bookList.add(value);
					}
				}
			}
		}
	} catch (Exception e) {
		System.out.println(e);
	}
	return bookList;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:25,代码来源:CasTimeBook.java


示例14: InsertTest

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Insert into IpUser Column Family
 */
public boolean InsertTest(String key, int val) {
	System.out.println("------------InsertTest--------------");

	try {
		ColumnParent parent = new ColumnParent("test");

		long timeStamp = System.currentTimeMillis();

		Column idColumnPageid = new Column();
		idColumnPageid.setName(this.cassandraUtil.toByteBuffer("signal"));
		idColumnPageid.setValue(this.cassandraUtil.toByteBuffer(String.valueOf(val)));
		idColumnPageid.setTimestamp(timeStamp);
		client.insert(this.cassandraUtil.toByteBuffer(key), parent, idColumnPageid, ConsistencyLevel.ONE);

	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return true;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:24,代码来源:TestClass.java


示例15: InsertTest2

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Insert into IpUser Column Family
 */
public boolean InsertTest2(int key, String val) {
	System.out.println("------------InsertTest--------------");

	try {
		ColumnParent parent = new ColumnParent("test");

		long timeStamp = System.currentTimeMillis();

		Column idColumnPageid = new Column();
		idColumnPageid.setName(this.cassandraUtil.toByteBuffer("content"));
		idColumnPageid.setValue(this.cassandraUtil.toByteBuffer(val));
		idColumnPageid.setTimestamp(timeStamp);
		client.insert(this.cassandraUtil.toByteBuffer(String.valueOf(key)), parent, idColumnPageid, ConsistencyLevel.ONE);

	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return true;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:24,代码来源:TestClass.java


示例16: InsertTest3

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Insert into IpUser Column Family
 */
public boolean InsertTest3(int userid, int key, String val) {
	System.out.println("------------InsertTest--------------");

	try {
		ColumnParent parent = new ColumnParent("test");

		long timeStamp = System.currentTimeMillis();

		Column idColumnPageid = new Column();
		idColumnPageid.setName(this.cassandraUtil.toByteBuffer(String.valueOf(key)));
		idColumnPageid.setValue(this.cassandraUtil.toByteBuffer(val));
		idColumnPageid.setTimestamp(timeStamp);
		client.insert(this.cassandraUtil.toByteBuffer(String.valueOf(userid)), parent, idColumnPageid, ConsistencyLevel.ONE);

	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return true;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:24,代码来源:TestClass.java


示例17: InsertIntoUserChapter

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
	 * Insert into CF -- "UserChapter"
	 * @param int userid: the key of column   like '119115'
	 * @param int signal: chapter's signal	  like '23'
	 * @param String content: chapter's value like '"07018720_1.0.0.0.0"'
	 */
	public boolean InsertIntoUserChapter(int userid, int signal, String content){
//		System.out.println("------------InsertIntoUserChapter--------------");

		try {
			ColumnParent parent = new ColumnParent("UserChapter");

			long timeStamp = System.currentTimeMillis();

			Column userChapter = new Column();
			userChapter.setName(this.cassandraUtil.toByteBuffer(String.valueOf(signal)));
			userChapter.setValue(this.cassandraUtil.toByteBuffer(content));
			userChapter.setTimestamp(timeStamp);
			client.insert(this.cassandraUtil.toByteBuffer(String.valueOf(userid)), parent, userChapter, ConsistencyLevel.QUORUM);

			return true;
			
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:28,代码来源:InsertChapterInfo.java


示例18: InsertIntoSignalChapterMap

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
	 * Insert into CF -- "SignalChapterMap"
	 * @param int signal: chapter's signal	  like '23'
	 * @param String content: chapter's value like '"07018720_1.0.0.0.0"'
	 */
	public boolean InsertIntoSignalChapterMap(int signal, String content){
//		System.out.println("------------InsertIntoSignalChapterMap--------------");

		try {
			ColumnParent parent = new ColumnParent("SignalChapterMap");

			long timeStamp = System.currentTimeMillis();

			Column signalChapter = new Column();
			signalChapter.setName(this.cassandraUtil.toByteBuffer("content"));
			signalChapter.setValue(this.cassandraUtil.toByteBuffer(content));
			signalChapter.setTimestamp(timeStamp);
			client.insert(this.cassandraUtil.toByteBuffer(String.valueOf(signal)), parent, signalChapter, ConsistencyLevel.QUORUM);
			
			return true;
			
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:27,代码来源:InsertChapterInfo.java


示例19: UpdateMaxid

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
/**
 * Update 'maxid' in CF 'ChapterSignalMap'
 */
public boolean UpdateMaxid(String signal) {
	
	try{
		ColumnParent parent = new ColumnParent("ChapterSignalMap");
		
		long timeStamp = System.currentTimeMillis();
		
		Column signalCol = new Column();
		signalCol.setName(this.cassandraUtil.toByteBuffer("maxid"));
		signalCol.setValue(this.cassandraUtil.toByteBuffer(signal));
		signalCol.setTimestamp(timeStamp);
		
		this.client.insert(this.cassandraUtil.toByteBuffer("maxid"), parent, signalCol, ConsistencyLevel.QUORUM);
		
	}catch(Exception e) {
		e.printStackTrace();
	}
	
	return true;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:24,代码来源:InsertChapterInfo.java


示例20: CassandraBase

import org.apache.cassandra.thrift.ConsistencyLevel; //导入依赖的package包/类
public CassandraBase(String instance, Map<String, String> config) {
    // The configuration has the following:
    // keyspace
    // columnParent
    // readConsitency (optional)
    // writeConsistency (optional)

    messageCatalog = new Messages("Cassandra");

    // The connection to Cassandra comes from RaptureCASSANDRA.cfg
    // and has host and port
    cassHost = MultiValueConfigLoader.getConfig("CASSANDRA-" + instance + ".host");
    if (cassHost == null) {
        cassHost = "localhost";
    }
    String cassPortString = MultiValueConfigLoader.getConfig("CASSANDRA-" + instance + ".port");
    if (cassPortString == null) {
        cassPortString = "9160";
    }
    cassPort = Integer.valueOf(cassPortString);

    keySpace = config.get(CassandraConstants.KEYSPACECFG);
    columnFamily = config.get(CassandraConstants.CFCFG);

    try {
        getConnection();
    } catch (TTransportException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), e);
    }
    ensureAllPresent();

    if (config.containsKey(CassandraConstants.READ_CONSISTENCY)) {
        readCL = ConsistencyLevel.valueOf(config.get(CassandraConstants.READ_CONSISTENCY));
    }

    if (config.containsKey(CassandraConstants.WRITE_CONSISTENCY)) {
        writeCL = ConsistencyLevel.valueOf(config.get(CassandraConstants.WRITE_CONSISTENCY));
    }

}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:41,代码来源:CassandraBase.java



注:本文中的org.apache.cassandra.thrift.ConsistencyLevel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FileImageOutputStreamSpi类代码示例发布时间:2022-05-21
下一篇:
Java InvalidInputException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap