List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY
null EMPTY_BYTE_ARRAY
To view the source code for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY.
Click Source Link
byte
array. From source file:com.bigdata.dastor.db.HintedHandOffManager.java
private static boolean sendMessage(InetAddress endPoint, String tableName, String cfName, String key) throws IOException { if (!Gossiper.instance.isKnownEndpoint(endPoint)) { logger_.warn("Hinted handoff found for endpoint " + endPoint.getHostAddress() + " which is not part of the gossip network. discarding."); return true; }/* ww w .j a va 2 s. c o m*/ if (!FailureDetector.instance.isAlive(endPoint)) { logger_.warn("Hinted handoff found for endpoint " + endPoint.getHostAddress() + " which is not alive. stopping."); return false; } Table table = Table.open(tableName); ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName); byte[] startColumn = ArrayUtils.EMPTY_BYTE_ARRAY; while (true) { QueryFilter filter = new SliceQueryFilter(key, new QueryPath(cfs.getColumnFamilyName()), startColumn, ArrayUtils.EMPTY_BYTE_ARRAY, false, PAGE_SIZE); ColumnFamily cf = cfs.getColumnFamily(filter); if (pagingFinished(cf, startColumn)) break; if (cf.getColumnNames().isEmpty()) { if (logger_.isDebugEnabled()) logger_.debug("Nothing to hand off for " + key); break; } startColumn = cf.getColumnNames().last(); RowMutation rm = new RowMutation(tableName, key); rm.add(cf); Message message = rm.makeRowMutationMessage(); WriteResponseHandler responseHandler = new WriteResponseHandler(1, tableName); // BIGDATA: retry int tryNum = 0; for (tryNum = 0; tryNum < 3; tryNum++) { MessagingService.instance.sendRR(message, new InetAddress[] { endPoint }, responseHandler); try { responseHandler.get(); break; } catch (TimeoutException e) { } } if (tryNum >= 3) { logger_.warn("Hinted handoff found for endpoint " + endPoint.getHostAddress() + " send message TimeoutException."); return false; } } return true; }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
public static byte[] getLengthCodedBinary(ByteBuf cb) { if (isLengthCodedLongNull(cb)) return null; int length = (int) getLengthCodedLong(cb); if (length == 0) return ArrayUtils.EMPTY_BYTE_ARRAY; return readBytes(cb, length); }
From source file:com.jaeksoft.searchlib.index.ObjectStorageDirectory.java
@Override public IndexInput openInput(String name) throws IOException { InputStream inputStream = null; try {//w ww. j a v a 2 s . c o m ByteCacheItem byteCacheItem = inputCache.get(name); if (byteCacheItem != null && byteCacheItem.bytes != null) return new Input(name, byteCacheItem.bytes); DownloadItem downloadItem = SwiftProtocol.readObject(httpDownloader, swiftToken, container, name); Long length = downloadItem.getContentLength(); if (length == null) throw new IOException("No content length"); if (byteCacheItem == null) byteCacheItem = new ByteCacheItem(); byteCacheItem.set(downloadItem.getContentLength(), downloadItem.getLastModified()); if (byteCacheItem.length > 0) { inputStream = downloadItem.getContentInputStream(); byteCacheItem.bytes = IOUtils.toByteArray(inputStream); inputStream.read(); } else byteCacheItem.bytes = ArrayUtils.EMPTY_BYTE_ARRAY; inputCache.add(name, byteCacheItem); return new Input(name, byteCacheItem.bytes); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } finally { IOUtils.close(inputStream); } }
From source file:com.facebook.infrastructure.db.RowMutation.java
public void delete(String columnFamilyColumn, long timestamp) { String[] values = RowMutation.getColumnAndColumnFamily(columnFamilyColumn); String cfName = values[0];/* ww w. ja v a 2 s .co m*/ if (modifications_.containsKey(cfName)) { throw new IllegalArgumentException("ColumnFamily " + cfName + " is already being modified"); } if (values.length == 0 || values.length > 3) throw new IllegalArgumentException("Column Family " + columnFamilyColumn + " in invalid format. Must be in <column family>:<column> format."); ColumnFamily columnFamily = modifications_.get(cfName); if (columnFamily == null) columnFamily = new ColumnFamily(cfName); if (values.length == 2) { if (columnFamily.isSuper()) { IColumn c = columnFamily.addColumn(values[1]); ((SuperColumn) c).markForDeleteAt(timestamp); } else { IColumn c = columnFamily.addColumn(values[1], ArrayUtils.EMPTY_BYTE_ARRAY, timestamp, true); } } else if (values.length == 3) { IColumn c = columnFamily.addColumn(values[1] + ":" + values[2], ArrayUtils.EMPTY_BYTE_ARRAY, timestamp, true); } else { assert values.length == 1; columnFamily.delete(timestamp); } modifications_.put(cfName, columnFamily); }
From source file:com.facebook.infrastructure.db.SuperColumn.java
public byte[] digest() { Set<IColumn> columns = columns_.getSortedColumns(); byte[] xorHash = ArrayUtils.EMPTY_BYTE_ARRAY; if (name_ == null) return xorHash; xorHash = name_.getBytes();/* www . java 2 s.co m*/ for (IColumn column : columns) { xorHash = FBUtilities.xor(xorHash, column.digest()); } return xorHash; }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationVisitorDispatch.java
@Override public void visit(MyExecuteLoadLogEvent packet) throws PEException { boolean switchToDb = true; ServerDBConnection conn = null;//from www . jav a2 s. com String dbName = packet.getDbName(); String origQuery = packet.getOrigQuery(); try { if (!this.includeDatabase(plugin, dbName)) { // still want to update log position if we filter out message updateBinLogPosition(packet, plugin); return; } conn = plugin.getServerDBConnection(); // If any session variables are to be set do it first plugin.getSessionVariableCache().setAllSessionVariableValues(conn); if (logger.isDebugEnabled()) { logger.debug("** START ExecuteLoadLog Event **"); if (switchToDb) logger.debug("USE " + dbName); logger.debug(origQuery); logger.debug("** END ExecuteLoadLog Event **"); } if (switchToDb) conn.setCatalog(dbName); // since we don't want to parse here to determine if a time function is specified // set the TIMESTAMP variable to the master statement execution time conn.executeUpdate("set " + VariableConstants.REPL_SLAVE_TIMESTAMP_NAME + "=" + packet.getCommonHeader().getTimestamp()); executeLDR(conn, plugin.getClientConnectionContext().getCtx(), origQuery.getBytes(CharsetUtil.UTF_8)); // start throwing down the bytes from the load data infile File infile = plugin.getInfileHandler().getInfile(packet.getFileId()); FileInputStream in = null; byte[] readData = new byte[MyExecuteLoadLogEvent.MAX_BUFFER_LEN]; try { in = new FileInputStream(infile); int len = in.read(readData); do { final byte[] readData1 = (len == MyExecuteLoadLogEvent.MAX_BUFFER_LEN) ? readData : ArrayUtils.subarray(readData, 0, len); executeLDB(conn, plugin.getClientConnectionContext().getCtx(), readData1); len = in.read(readData); } while (len > -1); executeLDB(conn, plugin.getClientConnectionContext().getCtx(), ArrayUtils.EMPTY_BYTE_ARRAY); } finally { IOUtils.closeQuietly(in); plugin.getInfileHandler().cleanUp(); } updateBinLogPosition(packet, plugin); } catch (Exception e) { if (plugin.validateErrorAndStop(packet.getErrorCode(), e)) { logger.error("Error occurred during replication processing: ", e); try { conn.execute("ROLLBACK"); } catch (SQLException e1) { throw new PEException("Error attempting to rollback after exception", e); // NOPMD by doug on 18/12/12 8:07 AM } } else { packet.setSkipErrors(true, "Replication Slave failed processing: '" + origQuery + "' but slave_skip_errors is active. Replication processing will continue"); } throw new PEException("Error executing: " + origQuery, e); } finally { // NOPMD by doug on 18/12/12 8:08 AM // Clear all the session variables since they are only good for one // event plugin.getSessionVariableCache().clearAllSessionVariables(); } }
From source file:mazewar.Mazewar.java
/** * The place where all the pieces are put together. *//* w ww. j a va 2s.c om*/ public Mazewar(String zkServer, int zkPort, int port, String name, String game, boolean robot) { super("ECE419 Mazewar"); consolePrintLn("ECE419 Mazewar started!"); /* Set up parent */ ZK_PARENT += game; // Throw up a dialog to get the GUIClient name. if (name != null) { clientId = name; } else { clientId = JOptionPane.showInputDialog("Enter your name"); } if ((clientId == null) || (clientId.length() == 0)) { Mazewar.quit(); } /* Connect to ZooKeeper and get sequencer details */ List<ClientNode> nodeList = null; try { zkWatcher = new ZkWatcher(); zkConnected = new CountDownLatch(1); zooKeeper = new ZooKeeper(zkServer + ":" + zkPort, ZK_TIMEOUT, new Watcher() { @Override public void process(WatchedEvent event) { /* Release Lock if ZooKeeper is connected */ if (event.getState() == SyncConnected) { zkConnected.countDown(); } else { System.err.println("Could not connect to ZooKeeper!"); System.exit(0); } } }); zkConnected.await(); /* Successfully connected, now create our node on ZooKeeper */ zooKeeper.create(Joiner.on('/').join(ZK_PARENT, clientId), Joiner.on(':').join(InetAddress.getLocalHost().getHostAddress(), port).getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); /* Get Seed from Parent */ mazeSeed = Long.parseLong(new String(zooKeeper.getData(ZK_PARENT, false, null))); /* Initialize Sequence Number */ sequenceNumber = new AtomicInteger(zooKeeper.exists(ZK_PARENT, false).getVersion()); /* Get list of nodes */ nodeList = ClientNode.sortList(zooKeeper.getChildren(ZK_PARENT, false)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Create the maze maze = new MazeImpl(new Point(mazeWidth, mazeHeight), mazeSeed); assert (maze != null); // Have the ScoreTableModel listen to the maze to find // out how to adjust scores. ScoreTableModel scoreModel = new ScoreTableModel(); assert (scoreModel != null); maze.addMazeListener(scoreModel); /* Initialize packet queue */ packetQueue = new ArrayBlockingQueue<MazePacket>(QUEUE_SIZE); sequencedQueue = new PriorityBlockingQueue<MazePacket>(QUEUE_SIZE, new Comparator<MazePacket>() { @Override public int compare(MazePacket o1, MazePacket o2) { return o1.sequenceNumber.compareTo(o2.sequenceNumber); } }); /* Inject Event Bus into Client */ Client.setEventBus(eventBus); /* Initialize ZMQ Context */ context = ZMQ.context(2); /* Set up publisher */ publisher = context.socket(ZMQ.PUB); publisher.bind("tcp://*:" + port); System.out.println("ZeroMQ Publisher Bound On: " + port); try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } /* Set up subscriber */ subscriber = context.socket(ZMQ.SUB); subscriber.subscribe(ArrayUtils.EMPTY_BYTE_ARRAY); clients = new ConcurrentHashMap<String, Client>(); try { for (ClientNode client : nodeList) { if (client.getName().equals(clientId)) { clientPath = ZK_PARENT + "/" + client.getPath(); guiClient = robot ? new RobotClient(clientId) : new GUIClient(clientId); clients.put(clientId, guiClient); maze.addClient(guiClient); eventBus.register(guiClient); subscriber.connect("tcp://" + new String(zooKeeper.getData(clientPath, false, null))); } else { addRemoteClient(client); } } } catch (Exception e) { e.printStackTrace(); } checkNotNull(guiClient, "Should have received our clientId in CLIENTS list!"); // Create the GUIClient and connect it to the KeyListener queue this.addKeyListener(guiClient); this.isRobot = robot; // Use braces to force constructors not to be called at the beginning of the // constructor. /*{ maze.addClient(new RobotClient("Norby")); maze.addClient(new RobotClient("Robbie")); maze.addClient(new RobotClient("Clango")); maze.addClient(new RobotClient("Marvin")); }*/ // Create the panel that will display the maze. overheadPanel = new OverheadMazePanel(maze, guiClient); assert (overheadPanel != null); maze.addMazeListener(overheadPanel); // Don't allow editing the console from the GUI console.setEditable(false); console.setFocusable(false); console.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); // Allow the console to scroll by putting it in a scrollpane JScrollPane consoleScrollPane = new JScrollPane(console); assert (consoleScrollPane != null); consoleScrollPane .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Console")); // Create the score table scoreTable = new JTable(scoreModel); assert (scoreTable != null); scoreTable.setFocusable(false); scoreTable.setRowSelectionAllowed(false); // Allow the score table to scroll too. JScrollPane scoreScrollPane = new JScrollPane(scoreTable); assert (scoreScrollPane != null); scoreScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Scores")); // Create the layout manager GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); getContentPane().setLayout(layout); // Define the constraints on the components. c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 3.0; c.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(overheadPanel, c); c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 2.0; c.weighty = 1.0; layout.setConstraints(consoleScrollPane, c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; layout.setConstraints(scoreScrollPane, c); // Add the components getContentPane().add(overheadPanel); getContentPane().add(consoleScrollPane); getContentPane().add(scoreScrollPane); // Pack everything neatly. pack(); // Let the magic begin. setVisible(true); overheadPanel.repaint(); this.requestFocusInWindow(); }
From source file:com.facebook.infrastructure.db.RowMutation.java
public static RowMutation getRowMutation(batch_mutation_super_t batchMutationSuper) { RowMutation rm = new RowMutation(batchMutationSuper.table, batchMutationSuper.key.trim()); Set keys = batchMutationSuper.cfmap.keySet(); Iterator keyIter = keys.iterator(); while (keyIter.hasNext()) { Object key = keyIter.next(); // Get the next key. List<superColumn_t> list = batchMutationSuper.cfmap.get(key); for (superColumn_t superColumnData : list) { if (superColumnData.columns.size() != 0) { for (column_t columnData : superColumnData.columns) { rm.add(key.toString() + ":" + superColumnData.name + ":" + columnData.columnName, columnData.value.getBytes(), columnData.timestamp); }/*from ww w .ja va2 s . c o m*/ } else { rm.add(key.toString() + ":" + superColumnData.name, ArrayUtils.EMPTY_BYTE_ARRAY, 0); } } } return rm; }
From source file:com.bigdata.dastor.db.HintedHandOffManager.java
private void deliverHintsToEndpoint(InetAddress endPoint) throws IOException, DigestMismatchException, InvalidRequestException, TimeoutException { queuedDeliveries.remove(endPoint);/*from w w w. jav a2 s . com*/ // BIGDATA: sleep a little, because sometimes, the immediate sending will fail. try { Thread.sleep(10000); } catch (InterruptedException e) { } logger_.info("Hinted handoff START for endPoint " + endPoint.getHostAddress()); long startTime = System.currentTimeMillis(); // 1. For each table and cf, scan through SystemTable.HintsColumnFamily to find all rows // of this edpoint. // 2. For each key (column) send application data to the endpoint. // 3. Delete the key (column) from SystemTable.HintsColumnFamily. // 4. Now force a flush // 5. Do major compaction to clean up all deletes etc. rowsReplayed = 0; // BIGDATA for JMX: change int to long deliveringEndPoint = endPoint; // BIGDATA for JMX ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF); delivery: for (String tableName : DatabaseDescriptor.getNonSystemTables()) // BIGDATA: ignore the system table { deliveringTable = tableName; // BIGDATA for JMX Set<String> cfs = Table.open(tableName).getColumnFamilies(); for (String cf : cfs) { deliveringCf = cf; long rowsReplayedOfCf = 0; byte[] startColumn = ArrayUtils.EMPTY_BYTE_ARRAY; String hintKey = makeHintKey(endPoint.getHostAddress(), tableName, cf); while (true) { QueryFilter filter = new SliceQueryFilter(hintKey, new QueryPath(HINTS_CF), startColumn, ArrayUtils.EMPTY_BYTE_ARRAY, false, PAGE_SIZE); ColumnFamily hintColumnFamily = ColumnFamilyStore .removeDeleted(hintStore.getColumnFamily(filter), Integer.MAX_VALUE); if (pagingFinished(hintColumnFamily, startColumn)) break; Collection<IColumn> keys = hintColumnFamily.getSortedColumns(); for (IColumn keyColumn : keys) { String keyStr = new String(keyColumn.name(), "UTF-8"); if (logger_.isDebugEnabled()) logger_.debug( String.format("Hinted handoff SENDING key %s to endpoint %s for kfsf %s:%s", keyStr, endPoint.getHostAddress(), tableName, cf)); if (sendMessage(endPoint, tableName, cf, keyStr)) { deleteHintKey(hintKey, keyColumn.name()); rowsReplayed++; rowsReplayedOfCf++; } else { logger_.warn(String.format( "Hinted handoff STOP, could not complete hinted handoff to %s when sending %s for kfsf %s:%s", endPoint.getHostAddress(), keyStr, tableName, cf)); // BIGDATA: here, the hinted data cannot be completely sent to the endPoint. // It may because the endPoint is down again. // the break will stop this hinted-handoff, and only another endpoint up/down can trigger another hinted-handoff. break delivery; } startColumn = keyColumn.name(); } logger_.info(String.format("Hinted handoff PROGRESS, have sent %s/%s rows to %s for kfsf %s:%s", rowsReplayedOfCf, rowsReplayed, endPoint.getHostAddress(), tableName, cf)); } if (rowsReplayedOfCf > 0) { logger_.info(String.format( "Hinted handoff DONE of %s rows to endpoint %s for kscf %s:%s, used time(ms):%s", rowsReplayedOfCf, endPoint.getHostAddress(), tableName, cf, System.currentTimeMillis() - startTime)); } } } if (rowsReplayed > 0) { try { hintStore.forceBlockingFlush(); // BIGDATA: changed to blockingFlush CompactionManager.instance.submitMajor(hintStore, 0, Integer.MAX_VALUE).get(); } catch (Exception e) { throw new RuntimeException(e); } } logger_.info(String.format("Hinted handoff FINISHED of %s rows to endpoint %s, used time(ms):%s", rowsReplayed, endPoint.getHostAddress(), System.currentTimeMillis() - startTime)); // BIGDATA: clean JMX rowsReplayed = 0; deliveringEndPoint = null; deliveringTable = null; deliveringCf = null; }
From source file:com.palantir.atlasdb.keyvalue.impl.AbstractAtlasDbKeyValueServiceTest.java
@Test public void testTableMetadata() { assertEquals(AtlasDbConstants.GENERIC_TABLE_METADATA.length, keyValueService.getMetadataForTable(TEST_TABLE).length); keyValueService.putMetadataForTable(TEST_TABLE, ArrayUtils.EMPTY_BYTE_ARRAY); assertEquals(0, keyValueService.getMetadataForTable(TEST_TABLE).length); keyValueService.putMetadataForTable(TEST_TABLE, metadata0); assertTrue(Arrays.equals(metadata0, keyValueService.getMetadataForTable(TEST_TABLE))); }