├── stats └── src │ ├── test │ ├── resources │ │ ├── serialization │ │ │ ├── HyperLogLog-1024-10.ser │ │ │ ├── HyperLogLog-2048-10.ser │ │ │ ├── HyperLogLog-4096-10.ser │ │ │ ├── HyperLogLog-1024-100.ser │ │ │ ├── HyperLogLog-1024-1000.ser │ │ │ ├── HyperLogLog-2048-100.ser │ │ │ ├── HyperLogLog-2048-1000.ser │ │ │ ├── HyperLogLog-4096-100.ser │ │ │ ├── HyperLogLog-4096-1000.ser │ │ │ ├── HyperLogLog-1024-10000.ser │ │ │ ├── HyperLogLog-1024-100000.ser │ │ │ ├── HyperLogLog-2048-10000.ser │ │ │ ├── HyperLogLog-2048-100000.ser │ │ │ ├── HyperLogLog-4096-10000.ser │ │ │ ├── HyperLogLog-4096-100000.ser │ │ │ ├── HyperLogLog-1024-10.raw │ │ │ ├── HyperLogLog-1024-100.raw │ │ │ ├── HyperLogLog-1024-1000.raw │ │ │ └── HyperLogLog-1024-10000.raw │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── facebook │ │ └── stats │ │ ├── TestingClock.java │ │ ├── TestHashBasedTopK.java │ │ ├── TestTreeBasedTopK.java │ │ ├── TestTreeBasedIntegerTopK.java │ │ └── TestArrayBasedIntegerTopK.java │ └── main │ └── java │ └── com │ └── facebook │ └── stats │ ├── Clock.java │ ├── EventRate.java │ ├── cardinality │ ├── Numbers.java │ └── Estimator.java │ ├── RealtimeClock.java │ ├── WritableMultiWindowStat.java │ ├── EventCounter.java │ ├── ReadableMultiWindowCounter.java │ ├── topk │ └── TopK.java │ ├── GaugeCounterFactory.java │ ├── AssociativeAggregation.java │ ├── ReadableMultiWindowGauge.java │ ├── FastGaugeCounterFactory.java │ ├── ReadableMultiWindowRate.java │ ├── DefaultGaugeCounterFactory.java │ ├── GaugeCounter.java │ ├── MaxEventCounter.java │ ├── MinEventCounter.java │ └── FacebookStatsReporter.java ├── logging ├── README.txt └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── logging │ │ ├── LogProvider.java │ │ └── InstanceLogProvider.java │ ├── jmh │ └── resources │ │ └── log4j.properties │ └── test │ └── resources │ └── log4j.properties ├── src └── license │ └── LICENSE-HEADER.txt ├── README.md ├── .gitignore ├── collections └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── collections │ │ ├── Factory.java │ │ ├── Trackable.java │ │ ├── creation │ │ └── Prototype.java │ │ ├── specialized │ │ ├── NumberType.java │ │ ├── LongTupleHeap.java │ │ ├── HashSetFactory.java │ │ ├── SnapshotableSet.java │ │ ├── SynchronizedSetFactory.java │ │ ├── SnapshotableSetImplFactory.java │ │ └── MutableByteArrayOutputStream.java │ │ ├── SetFactory.java │ │ ├── InvertibleMapper.java │ │ ├── ConcurrentSetMap.java │ │ ├── SimpleHeapFactory.java │ │ ├── UniTriple.java │ │ ├── ReadOnlyMixedTypeMap.java │ │ ├── ConcurrentSetFactory.java │ │ ├── StringKeyedMixTypedMap.java │ │ ├── ListMapper.java │ │ ├── EntryValueMapper.java │ │ ├── SnapshotProvider.java │ │ ├── WrappedIterator.java │ │ └── TranslatingIterable.java │ └── test │ └── resources │ └── log4j.properties ├── testing └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── testing │ │ └── Function.java │ └── test │ └── resources │ └── log4j.properties ├── concurrency └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── concurrency │ │ ├── TrackedRunnable.java │ │ ├── Reapable.java │ │ ├── TrackedCallable.java │ │ ├── ExecutorServiceFactory.java │ │ ├── NoOp.java │ │ ├── Completable.java │ │ ├── CountTask.java │ │ ├── FixedValueCallable.java │ │ ├── linearization │ │ └── ConcurrentPoint.java │ │ ├── ValueFactory.java │ │ ├── NullExceptionHandler.java │ │ ├── SingletonExecutorServiceFactory.java │ │ ├── NamedDaemonThreadFactory.java │ │ ├── RuntimeExceptionHandler.java │ │ ├── CastingExceptionHandler.java │ │ ├── CriticalSectionFactory.java │ │ ├── ErrorLoggingRunnable.java │ │ ├── EvictionListener.java │ │ └── CallableSnapshotFunction.java │ └── test │ ├── java │ └── com │ │ └── facebook │ │ └── concurrency │ │ ├── TestCoreConcurrentCache.java │ │ └── TestCaffeineConcurrentCache.java │ └── resources │ └── log4j.properties ├── concurrent-stats ├── src │ └── main │ │ └── java │ │ └── com │ │ └── facebook │ │ └── stats │ │ └── concurrent │ │ └── Stat.java └── README.md ├── tools └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── tools │ │ ├── subprocess │ │ ├── RedirectErrorsTo.java │ │ └── ProcessBuilderWrapper.java │ │ ├── io │ │ ├── Input.java │ │ ├── YesNo.java │ │ ├── StatusPrintStream.java │ │ ├── Answer.java │ │ ├── Status.java │ │ └── NullOutputStream.java │ │ ├── CommandBuilder.java │ │ └── parser │ │ └── CliConverter.java │ └── test │ └── java │ └── com │ └── facebook │ └── tools │ └── example │ └── CheckpointManager.java ├── collections-foundation └── src │ └── main │ └── java │ └── com │ └── facebook │ └── collectionsbase │ ├── Mapper.java │ ├── Courier.java │ ├── Filter.java │ ├── Function.java │ ├── FunctionToMapper.java │ └── SafeFunction.java ├── util └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── util │ │ ├── digest │ │ ├── DigestFunction.java │ │ ├── IntegerIdentityDigest.java │ │ ├── IntegerDigestFunction.java │ │ └── LongIdentityDigestFunction.java │ │ ├── RefreshableExtSupplier.java │ │ ├── exceptions │ │ ├── ExceptionHandler.java │ │ └── UncheckedCheckedException.java │ │ ├── serialization │ │ ├── SerDe.java │ │ ├── Serializer.java │ │ ├── Deserializer.java │ │ └── SerDeException.java │ │ ├── ExtCallable.java │ │ ├── Visitor.java │ │ ├── function │ │ ├── ExtUnaryOperator.java │ │ ├── ExtBinaryOperator.java │ │ ├── ExtToIntFunction.java │ │ ├── ExtIntFunction.java │ │ ├── ExtToLongFunction.java │ │ ├── ExtLongFunction.java │ │ ├── ExtLongToIntFunction.java │ │ ├── ExtIntToLongFunction.java │ │ ├── ExtToIntBiFunction.java │ │ ├── ExtDoubleFunction.java │ │ ├── ExtDoubleToIntFunction.java │ │ ├── ExtToLongBiFunction.java │ │ ├── ExtObjIntConsumer.java │ │ ├── ExtToDoubleFunction.java │ │ ├── ExtIntBinaryOperator.java │ │ ├── ExtDoubleToLongFunction.java │ │ ├── ExtIntToDoubleFunction.java │ │ ├── ExtObjLongConsumer.java │ │ ├── ExtLongBinaryOperator.java │ │ ├── ExtLongToDoubleFunction.java │ │ ├── ExtObjDoubleConsumer.java │ │ ├── ExtToDoubleBiFunction.java │ │ ├── ExtDoubleBinaryOperator.java │ │ ├── ExtIntSupplier.java │ │ ├── ExtLongSupplier.java │ │ ├── ExtConsumer.java │ │ ├── ExtDoubleSupplier.java │ │ ├── ExtBooleanSupplier.java │ │ ├── ExtIntConsumer.java │ │ ├── ExtBiFunction.java │ │ ├── ExtDoubleConsumer.java │ │ └── ExtLongConsumer.java │ │ ├── StringUtils.java │ │ ├── ExtSupplier.java │ │ └── StreamImporter.java │ └── test │ ├── java │ └── com │ │ └── facebook │ │ └── util │ │ ├── TestExtRunnable.java │ │ ├── TestExtSupplier.java │ │ ├── TestTimeUtil.java │ │ ├── function │ │ ├── TestExtIntSupplier.java │ │ ├── TestExtLongSupplier.java │ │ ├── TestExtBooleanSupplier.java │ │ └── TestExtDoubleSupplier.java │ │ └── digest │ │ └── TestLongMurmur3Hash.java │ └── resources │ └── log4j.properties ├── config └── src │ ├── main │ └── java │ │ └── com │ │ └── facebook │ │ └── config │ │ ├── dynamic │ │ ├── OptionWatcher.java │ │ ├── OptionTranslator.java │ │ └── Option.java │ │ ├── RefreshableConfigProvider.java │ │ ├── JSONProvider.java │ │ ├── ExtractableBeanBuilder.java │ │ ├── Extractor.java │ │ ├── ConfigProvider.java │ │ ├── EmptyJSONProvider.java │ │ ├── LongExtractor.java │ │ ├── DoubleExtractor.java │ │ ├── BooleanExtractor.java │ │ ├── IntegerExtractor.java │ │ ├── StringToPeriodMapper.java │ │ ├── JSONObjectExtractor.java │ │ ├── Refreshable.java │ │ ├── ConfigException.java │ │ ├── ClassExtractor.java │ │ ├── StringExtractor.java │ │ └── FieldExtractor.java │ └── test │ └── java │ └── com │ └── facebook │ └── config │ └── MockJSONProvider.java ├── lifecycle └── src │ └── test │ └── resources │ └── log4j.properties ├── memory └── src │ └── main │ └── java │ └── com │ └── facebook │ └── memory │ └── UnsafeAccessor.java └── CONTRIBUTING.md /stats/src/test/resources/serialization/HyperLogLog-1024-10.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-1024-10.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-2048-10.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-2048-10.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-4096-10.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-4096-10.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-100.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-1024-100.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-1000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-1024-1000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-2048-100.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-2048-100.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-2048-1000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-2048-1000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-4096-100.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-4096-100.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-4096-1000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-4096-1000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-10000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-1024-10000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-100000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-1024-100000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-2048-10000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-2048-10000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-2048-100000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-2048-100000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-4096-10000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-4096-10000.ser -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-4096-100000.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/jcommon/HEAD/stats/src/test/resources/serialization/HyperLogLog-4096-100000.ser -------------------------------------------------------------------------------- /logging/README.txt: -------------------------------------------------------------------------------- 1 | This module contains a logger-agnostic interface (though %-format inspired) and 2 | an implementation that uses slf4j for the backend. Additional implementations of 3 | Logger may be created using any logging framework, or use slf4j's many bridges. 4 | -------------------------------------------------------------------------------- /src/license/LICENSE-HEADER.txt: -------------------------------------------------------------------------------- 1 | COPYRIGHT_SECTION 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jcommon 2 | 3 | jcommon: a set of libraries used inside Facebook java projects, 4 | internal and open source. 5 | 6 | ## Requirements 7 | 8 | jcommon builds and is tested on both Java 8 and Java 11. 9 | 10 | ## Building jcommon 11 | 12 | Maven `pom.xml` files are provided as a convenience. However, we 13 | do not regularly test them, and do not consider them supported. 14 | 15 | ## Additional information 16 | 17 | We do not guarantee API or ABI stability. We do not tag specific 18 | versions, and no longer publish artifacts to Maven Central. 19 | 20 | Pull requests are permitted, but not regularly reviewed. 21 | 22 | ## License 23 | 24 | jcommon is provided under the Apache License version 2.0, as found in the 25 | LICENSE file. 26 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/Clock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | interface Clock { 19 | public long getMillis(); 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .DS_Store 3 | .arc 4 | .phutil_module_cache 5 | 6 | # idea project files 7 | .idea/ 8 | *.iml 9 | 10 | # ctags db 11 | /tags 12 | 13 | # etags db 14 | /TAGS 15 | 16 | # gtags db 17 | /GTAGS 18 | /GRTAGS 19 | /GPATH 20 | 21 | # idutils db 22 | /ID 23 | 24 | # eclipse project files 25 | .project 26 | .classpath 27 | .settings/ 28 | collections/pom.xml.releaseBackup 29 | concurrency/pom.xml.releaseBackup 30 | config/pom.xml.releaseBackup 31 | jcommon-all/pom.xml.releaseBackup 32 | json/pom.xml.releaseBackup 33 | lifecycle/pom.xml.releaseBackup 34 | logging/pom.xml.releaseBackup 35 | memory/pom.xml.releaseBackup 36 | pom.xml.releaseBackup 37 | release.properties 38 | stats/pom.xml.releaseBackup 39 | testing/pom.xml.releaseBackup 40 | tmp/the-mess.tar 41 | util/pom.xml.releaseBackup 42 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/Factory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | public interface Factory { 19 | T create(); 20 | } 21 | -------------------------------------------------------------------------------- /logging/src/main/java/com/facebook/logging/LogProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.logging; 17 | 18 | public interface LogProvider { 19 | public Logger get(); 20 | } 21 | -------------------------------------------------------------------------------- /testing/src/main/java/com/facebook/testing/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.testing; 17 | 18 | public interface Function { 19 | public void execute(T argument); 20 | } 21 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/Trackable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | public interface Trackable { 19 | public boolean hasChanged(); 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/TrackedRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public interface TrackedRunnable extends Runnable, Completable {} 19 | -------------------------------------------------------------------------------- /concurrent-stats/src/main/java/com/facebook/stats/concurrent/Stat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats.concurrent; 17 | 18 | public interface Stat { 19 | void update(long value); 20 | } 21 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/subprocess/RedirectErrorsTo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.subprocess; 17 | 18 | enum RedirectErrorsTo { 19 | STDERR, 20 | STDOUT, 21 | } 22 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | public interface Mapper { 19 | public Y map(X input); 20 | } 21 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/creation/Prototype.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.creation; 17 | 18 | public interface Prototype { 19 | public X copyOfMe(); 20 | } 21 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/digest/DigestFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.digest; 17 | 18 | public interface DigestFunction { 19 | public long computeDigest(T input); 20 | } 21 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/EventRate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | public interface EventRate { 19 | public void add(long delta); 20 | 21 | public long getValue(); 22 | } 23 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/NumberType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | public enum NumberType { 19 | INTEGER, 20 | LONG, 21 | ; 22 | } 23 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/Reapable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public interface Reapable { 19 | public void shutdown() throws E; 20 | } 21 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/Input.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | public interface Input extends Iterable { 19 | public int read(); 20 | 21 | public String readLine(); 22 | } 23 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/Courier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | public interface Courier { 19 | public boolean isSet(); 20 | 21 | public T get(); 22 | } 23 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/dynamic/OptionWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config.dynamic; 17 | 18 | public interface OptionWatcher { 19 | public void propertyUpdated(V value) throws Exception; 20 | } 21 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/RefreshableExtSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | public interface RefreshableExtSupplier extends ExtSupplier { 19 | void reset(); 20 | } 21 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/SetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import java.util.Set; 19 | 20 | public interface SetFactory> { 21 | public S create(); 22 | } 23 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/exceptions/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.exceptions; 17 | 18 | public interface ExceptionHandler { 19 | public T handle(S e); 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/TrackedCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.Callable; 19 | 20 | public interface TrackedCallable extends Callable, Completable {} 21 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/cardinality/Numbers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats.cardinality; 17 | 18 | class Numbers { 19 | public static boolean isPowerOf2(long value) { 20 | return (value & value - 1) == 0; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/RealtimeClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | class RealtimeClock implements Clock { 19 | @Override 20 | public long getMillis() { 21 | return System.currentTimeMillis(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/serialization/SerDe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.serialization; 17 | 18 | /** 19 | * marker interface 20 | * 21 | * @param 22 | */ 23 | public interface SerDe extends Serializer, Deserializer {} 24 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/InvertibleMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import com.facebook.collectionsbase.Mapper; 19 | 20 | public interface InvertibleMapper extends Mapper { 21 | public X unmap(Y input); 22 | } 23 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/ExecutorServiceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.ExecutorService; 19 | 20 | public interface ExecutorServiceFactory { 21 | T create(); 22 | } 23 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/WritableMultiWindowStat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | public interface WritableMultiWindowStat { 19 | /** @param value value to add to the underlying multi-window statistic */ 20 | public void add(long value); 21 | } 22 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/RefreshableConfigProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | /** Marker interface for objects that implement both Refreshable and ConfigProvider */ 19 | public interface RefreshableConfigProvider extends Refreshable, ConfigProvider {} 20 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/NoOp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public class NoOp implements Runnable { 19 | public static final Runnable INSTANCE = new NoOp(); 20 | 21 | private NoOp() {} 22 | 23 | @Override 24 | public void run() {} 25 | } 26 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/digest/IntegerIdentityDigest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.digest; 17 | 18 | public class IntegerIdentityDigest implements DigestFunction { 19 | @Override 20 | public long computeDigest(Integer input) { 21 | return input; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/JSONProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | /** Interface for providing JSON Objects */ 22 | public interface JSONProvider { 23 | public JSONObject get() throws JSONException; 24 | } 25 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/ConcurrentSetMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import java.util.Set; 19 | 20 | public class ConcurrentSetMap extends SetMapImpl> { 21 | public ConcurrentSetMap() { 22 | super(new ConcurrentSetFactory<>()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/EventCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | /** 19 | * marker interface: this is required for for any class that requires a generic of the type C 20 | * extends EventCounterIf 21 | */ 22 | public interface EventCounter extends EventCounterIf {} 23 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/ReadableMultiWindowCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | public interface ReadableMultiWindowCounter { 19 | public long getMinuteValue(); 20 | 21 | public long getTenMinuteValue(); 22 | 23 | public long getHourValue(); 24 | 25 | public long getAllTimeValue(); 26 | } 27 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/topk/TopK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats.topk; 17 | 18 | import java.util.List; 19 | 20 | /* 21 | * Interface for streaming top-k algorithms. 22 | */ 23 | public interface TopK> { 24 | public void add(T key, long count); 25 | 26 | public List getTopK(); 27 | } 28 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/SimpleHeapFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | public interface SimpleHeapFactory> { 19 | /** 20 | * @param initialSize hint to be used to size the heap initially 21 | * @return 22 | */ 23 | public S create(int initialSize); 24 | } 25 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/GaugeCounterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import org.joda.time.ReadableDateTime; 19 | 20 | /** Factory interface for creating new GaugeCounters */ 21 | public interface GaugeCounterFactory { 22 | public GaugeCounter create(ReadableDateTime start, ReadableDateTime end); 23 | } 24 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/CommandBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools; 17 | 18 | import com.facebook.tools.parser.CliCommand; 19 | import com.facebook.tools.parser.CliParser; 20 | 21 | public interface CommandBuilder { 22 | public CliCommand defineCommand(); 23 | 24 | public void runCommand(CliParser parser); 25 | } 26 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/Completable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | /** 19 | * implementations may vary wildly, but typically this is for an object that wants to do any cleanup 20 | * or bookkeeping when it's finished 21 | */ 22 | public interface Completable { 23 | public void complete(); 24 | } 25 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/ExtractableBeanBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | // interface that both indicates annotated fields for how to construct a builder 19 | // fromJSON as well as a method to construct a specified object type (T) 20 | public interface ExtractableBeanBuilder { 21 | public T build(); 22 | } 23 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/Extractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | // how to extract a particular type from a JSONObject 22 | public interface Extractor { 23 | public V extract(String key, JSONObject jsonObject) throws JSONException; 24 | } 25 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/ConfigProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | public interface ConfigProvider { 19 | /** 20 | * Provides an accessor for a config source 21 | * 22 | * @return - ConfigAccessor 23 | * @throws ConfigException 24 | */ 25 | public ConfigAccessor getConfig() throws ConfigException; 26 | } 27 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/EmptyJSONProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class EmptyJSONProvider implements JSONProvider { 22 | @Override 23 | public JSONObject get() throws JSONException { 24 | return new JSONObject(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/YesNo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | public enum YesNo { 19 | @Answer({"y", "yes"}) 20 | YES, 21 | 22 | @Answer({"n", "no"}) 23 | NO; 24 | 25 | public boolean isYes() { 26 | return this == YES; 27 | } 28 | 29 | public boolean isNo() { 30 | return this == NO; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/UniTriple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | /** 19 | * Three elements of the same type if only java had tuples... 20 | * 21 | * @param 22 | */ 23 | public class UniTriple extends Triple { 24 | public UniTriple(T t, T t1, T t2) { 25 | super(t, t1, t2); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/ReadOnlyMixedTypeMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import com.google.common.reflect.TypeToken; 19 | 20 | public interface ReadOnlyMixedTypeMap { 21 | V get(K id, Class clazz); 22 | 23 | V get(K id, TypeToken type); 24 | 25 | V get(Key key); 26 | 27 | int size(); 28 | } 29 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/ExtCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import java.util.concurrent.Callable; 19 | 20 | public interface ExtCallable { 21 | V call() throws E; 22 | 23 | static Callable quiet(ExtCallable callable) { 24 | return () -> ExtSupplier.quiet(() -> callable.call()).get(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/StatusPrintStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | import java.io.OutputStream; 19 | 20 | @SuppressWarnings("AbstractClassExtendsConcreteClass") 21 | public abstract class StatusPrintStream extends PrintStreamPlus implements Status { 22 | protected StatusPrintStream(OutputStream out) { 23 | super(out); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/LongExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class LongExtractor implements Extractor { 22 | @Override 23 | public Long extract(String key, JSONObject jsonObject) throws JSONException { 24 | return jsonObject.getLong(key); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/Visitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | /** 19 | * simple visitor object for type T 20 | * 21 | * @param 22 | */ 23 | public interface Visitor { 24 | /** 25 | * @param element element being examined 26 | * @return return true to continue visiting to next element 27 | */ 28 | public boolean visit(T element); 29 | } 30 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/LongTupleHeap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.SimpleHeap; 19 | 20 | /** marker interface; also binds some return types more tightly (makeCopy) */ 21 | public interface LongTupleHeap extends SimpleHeap { 22 | @Override 23 | LongTupleHeap makeCopy(); 24 | } 25 | -------------------------------------------------------------------------------- /logging/src/main/java/com/facebook/logging/InstanceLogProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.logging; 17 | 18 | public class InstanceLogProvider implements LogProvider { 19 | private final Logger logger; 20 | 21 | public InstanceLogProvider(Logger logger) { 22 | this.logger = logger; 23 | } 24 | 25 | @Override 26 | public Logger get() { 27 | return logger; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/cardinality/Estimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats.cardinality; 17 | 18 | interface Estimator { 19 | boolean setIfGreater(int bucket, int highestBitPosition); 20 | 21 | long estimate(); 22 | 23 | int estimateSizeInBytes(); 24 | 25 | int[] buckets(); 26 | 27 | int getNumberOfBuckets(); 28 | 29 | int getMaxAllowedBucketValue(); 30 | } 31 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/digest/IntegerDigestFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.digest; 17 | 18 | public class IntegerDigestFunction implements DigestFunction { 19 | private final MurmurHash hasher = new MurmurHash(MurmurHash.JCOMMON_SEED); 20 | 21 | @Override 22 | public long computeDigest(Integer input) { 23 | return hasher.hash(input); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/DoubleExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class DoubleExtractor implements Extractor { 22 | @Override 23 | public Double extract(String key, JSONObject jsonObject) throws JSONException { 24 | return jsonObject.getDouble(key); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/BooleanExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class BooleanExtractor implements Extractor { 22 | @Override 23 | public Boolean extract(String key, JSONObject jsonObject) throws JSONException { 24 | return jsonObject.getBoolean(key); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/IntegerExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class IntegerExtractor implements Extractor { 22 | @Override 23 | public Integer extract(String key, JSONObject jsonObject) throws JSONException { 24 | return jsonObject.getInt(key); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/StringToPeriodMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import com.facebook.collectionsbase.Mapper; 19 | import org.joda.time.Period; 20 | 21 | public class StringToPeriodMapper implements Mapper { 22 | @Override 23 | public Period map(String input) { 24 | return new Period(ConfigUtil.getDurationMillis(input)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | /** 19 | * full filter capability: take an input, return True/False, and throw checked exceptions or even 20 | * Error types if necessary 21 | * 22 | * @param 23 | * @param 24 | */ 25 | public interface Filter extends Function {} 26 | -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-10.raw: -------------------------------------------------------------------------------- 1 | 2 |  -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-100.raw: -------------------------------------------------------------------------------- 1 |  2 |  -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-1000.raw: -------------------------------------------------------------------------------- 1 |  2 |   -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/Answer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Target(ElementType.FIELD) 25 | public @interface Answer { 26 | String[] value(); 27 | } 28 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/HashSetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.SetFactory; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | public class HashSetFactory implements SetFactory> { 23 | @Override 24 | public Set create() { 25 | return new HashSet<>(64); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/JSONObjectExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class JSONObjectExtractor implements Extractor { 22 | @Override 23 | public JSONObject extract(String key, JSONObject jsonObject) throws JSONException { 24 | return jsonObject.getJSONObject(key); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.UnaryOperator; 19 | 20 | public interface ExtUnaryOperator extends ExtFunction { 21 | static UnaryOperator quiet(ExtUnaryOperator unaryOperator) { 22 | return (a) -> ExtFunction.quiet(unaryOperator).apply(a); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/Refreshable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | /** 19 | * object that supports the idea of being 'refreshed'. Example: a config file accessor that parses 20 | * the file once and stores it for access. It may implement this interface so that it may be 21 | * reloaded on-demand 22 | */ 23 | public interface Refreshable { 24 | public void refresh() throws ConfigException; 25 | } 26 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.BinaryOperator; 19 | 20 | public interface ExtBinaryOperator extends ExtBiFunction { 21 | static BinaryOperator quiet(ExtBinaryOperator binaryOperator) { 22 | return (a, b) -> ExtBiFunction.quiet(binaryOperator).apply(a, b); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/SnapshotableSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.SnapshotProvider; 19 | import java.util.Set; 20 | 21 | /** 22 | * maker interface that is a Set that also implements SnapshotProvider 23 | * 24 | * @param 25 | */ 26 | public interface SnapshotableSet extends Set, SnapshotProvider> {} 27 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/ConcurrentSetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import java.util.Collections; 19 | import java.util.Set; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | public class ConcurrentSetFactory implements SetFactory> { 23 | @Override 24 | public Set create() { 25 | return Collections.newSetFromMap(new ConcurrentHashMap<>()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/CountTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.atomic.AtomicLong; 19 | 20 | public class CountTask implements Runnable { 21 | private final AtomicLong count = new AtomicLong(0); 22 | 23 | @Override 24 | public void run() { 25 | count.incrementAndGet(); 26 | } 27 | 28 | public long getValue() { 29 | return count.get(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/AssociativeAggregation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | /** 19 | * Aggregation operation that maintains the associative property on multiple combinations. An 20 | * aggregation is associative if the order in which the operations are performed does not matter 21 | * (e.g. sum, max, min). 22 | */ 23 | public interface AssociativeAggregation { 24 | public long combine(long l1, long l2); 25 | } 26 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/TestExtRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import java.util.function.Supplier; 19 | 20 | public class TestExtRunnable extends TestQuietFunctionBase { 21 | @Override 22 | protected void throwFromQuiet(Supplier toThrow) { 23 | ExtRunnable.quiet( 24 | () -> { 25 | throw toThrow.get(); 26 | }) 27 | .run(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/TestExtSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import java.util.function.Supplier; 19 | 20 | public class TestExtSupplier extends TestQuietFunctionBase { 21 | @Override 22 | protected void throwFromQuiet(Supplier toThrow) { 23 | ExtSupplier.quiet( 24 | () -> { 25 | throw toThrow.get(); 26 | }) 27 | .get(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | /** 19 | * full function capability: take an input, product an output, and throw checked exceptions or even 20 | * Error types if necessary 21 | * 22 | * @param 23 | * @param 24 | * @param 25 | */ 26 | public interface Function { 27 | public V execute(K input) throws E; 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/FixedValueCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.Callable; 19 | 20 | public class FixedValueCallable implements Callable { 21 | private final V value; 22 | 23 | public FixedValueCallable(V value) { 24 | this.value = value; 25 | } 26 | 27 | @Override 28 | public V call() throws Exception { 29 | return value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/linearization/ConcurrentPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency.linearization; 17 | 18 | /** 19 | * Effectively a read lock. Once start() is called, any call to LinearizationPoint.start() will 20 | * block 21 | * 22 | *

NOTE: use start/complete in a try/finally block the same as Lock 23 | */ 24 | public interface ConcurrentPoint { 25 | public void start(); 26 | 27 | public void complete(); 28 | } 29 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToIntFunction; 19 | 20 | public interface ExtToIntFunction { 21 | int applyAsInt(T value) throws E; 22 | 23 | static ToIntFunction quiet(ExtToIntFunction toIntFunction) { 24 | return (value) -> ExtIntSupplier.quiet(() -> toIntFunction.applyAsInt(value)).getAsInt(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/ValueFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public interface ValueFactory { 19 | /** 20 | * Given some input of type I, creates an output object of type O, or throws an exception of type 21 | * E if there was some trouble creating it. 22 | * 23 | * @param input 24 | * @return 25 | * @throws E 26 | */ 27 | public O create(I input) throws E; 28 | } 29 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/dynamic/OptionTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config.dynamic; 17 | 18 | import com.google.common.base.Function; 19 | 20 | public class OptionTranslator extends OptionImpl { 21 | public OptionTranslator(Option option, Function translator) { 22 | setValue(translator.apply(option.getValue())); 23 | option.addWatcher(value -> setValue(translator.apply(option.getValue()))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/ReadableMultiWindowGauge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | public interface ReadableMultiWindowGauge extends ReadableMultiWindowRate { 19 | long getMinuteSamples(); 20 | 21 | long getMinuteAvg(); 22 | 23 | long getTenMinuteSamples(); 24 | 25 | long getTenMinuteAvg(); 26 | 27 | long getHourSamples(); 28 | 29 | long getHourAvg(); 30 | 31 | long getAllTimeSamples(); 32 | 33 | long getAllTimeAvg(); 34 | } 35 | -------------------------------------------------------------------------------- /stats/src/test/resources/serialization/HyperLogLog-1024-10000.raw: -------------------------------------------------------------------------------- 1 |    2 |   3 |   4 |  5 |   6 |  7 |         8 |   9 |   10 |  11 |        12 |    13 |   14 |    -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/StringKeyedMixTypedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * * marker interface for commonly used type 22 | * 23 | * @param 24 | */ 25 | public class StringKeyedMixTypedMap extends MixedTypeMap { 26 | public StringKeyedMixTypedMap(Map, Object> map) { 27 | super(map); 28 | } 29 | 30 | public StringKeyedMixTypedMap() {} 31 | } 32 | -------------------------------------------------------------------------------- /concurrency/src/test/java/com/facebook/concurrency/TestCoreConcurrentCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public class TestCoreConcurrentCache extends AbstractTestConcurrentCache { 19 | 20 | @Override 21 | protected ConcurrentCache createCache( 22 | ValueFactory valueFactory) { 23 | return new CoreConcurrentCache<>(valueFactory, RuntimeExceptionHandler.INSTANCE); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/FastGaugeCounterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import org.joda.time.ReadableDateTime; 19 | 20 | public class FastGaugeCounterFactory implements GaugeCounterFactory { 21 | public static GaugeCounterFactory INSTANCE = new FastGaugeCounterFactory(); 22 | 23 | @Override 24 | public GaugeCounter create(ReadableDateTime start, ReadableDateTime end) { 25 | return new FastGaugeCounter(start, end); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtSupplier; 19 | import java.util.function.IntFunction; 20 | 21 | public interface ExtIntFunction { 22 | R apply(int value) throws E; 23 | 24 | static IntFunction quiet(ExtIntFunction intFunction) { 25 | return (value) -> ExtSupplier.quiet(() -> intFunction.apply(value)).get(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToLongFunction; 19 | 20 | public interface ExtToLongFunction { 21 | long applyAsLong(T value) throws E; 22 | 23 | static ToLongFunction quiet(ExtToLongFunction toLongFunction) { 24 | return (value) -> ExtLongSupplier.quiet(() -> toLongFunction.applyAsLong(value)).getAsLong(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/ConfigException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | public class ConfigException extends RuntimeException { 19 | public ConfigException() {} 20 | 21 | public ConfigException(String message) { 22 | super(message); 23 | } 24 | 25 | public ConfigException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | 29 | public ConfigException(Throwable cause) { 30 | super(cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/ReadableMultiWindowRate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | public interface ReadableMultiWindowRate { 19 | public long getMinuteSum(); 20 | 21 | public long getMinuteRate(); 22 | 23 | public long getTenMinuteSum(); 24 | 25 | public long getTenMinuteRate(); 26 | 27 | public long getHourSum(); 28 | 29 | public long getHourRate(); 30 | 31 | public long getAllTimeSum(); 32 | 33 | public long getAllTimeRate(); 34 | } 35 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/exceptions/UncheckedCheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.exceptions; 17 | 18 | /** 19 | * This exception represents a checked exception that was caught and re-thrown as a {@link 20 | * RuntimeException}. 21 | */ 22 | public class UncheckedCheckedException extends RuntimeException { 23 | private static final long serialVersionUID = 1L; 24 | 25 | public UncheckedCheckedException(Throwable t) { 26 | super(t); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtSupplier; 19 | import java.util.function.LongFunction; 20 | 21 | public interface ExtLongFunction { 22 | R apply(long value) throws E; 23 | 24 | static LongFunction quiet(ExtLongFunction longFunction) { 25 | return (value) -> ExtSupplier.quiet(() -> longFunction.apply(value)).get(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.LongToIntFunction; 19 | 20 | public interface ExtLongToIntFunction { 21 | int applyAsInt(long value) throws E; 22 | 23 | static LongToIntFunction quiet(ExtLongToIntFunction longToIntFunction) { 24 | return (value) -> ExtIntSupplier.quiet(() -> longToIntFunction.applyAsInt(value)).getAsInt(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/DefaultGaugeCounterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import org.joda.time.ReadableDateTime; 19 | 20 | public class DefaultGaugeCounterFactory implements GaugeCounterFactory { 21 | public static GaugeCounterFactory INSTANCE = new DefaultGaugeCounterFactory(); 22 | 23 | @Override 24 | public GaugeCounter create(ReadableDateTime start, ReadableDateTime end) { 25 | return new DefaultGaugeCounter(start, end); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.IntToLongFunction; 19 | 20 | public interface ExtIntToLongFunction { 21 | long applyAsLong(int value) throws E; 22 | 23 | static IntToLongFunction quiet(ExtIntToLongFunction intToLongFunction) { 24 | return (value) -> ExtLongSupplier.quiet(() -> intToLongFunction.applyAsLong(value)).getAsLong(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToIntBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToIntBiFunction; 19 | 20 | public interface ExtToIntBiFunction { 21 | int applyAsInt(T t, U u) throws E; 22 | 23 | static ToIntBiFunction quiet(ExtToIntBiFunction toIntBiFunction) { 24 | return (t, u) -> ExtIntSupplier.quiet(() -> toIntBiFunction.applyAsInt(t, u)).getAsInt(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtSupplier; 19 | import java.util.function.DoubleFunction; 20 | 21 | public interface ExtDoubleFunction { 22 | R apply(double value) throws E; 23 | 24 | static DoubleFunction quiet(ExtDoubleFunction doubleFunction) { 25 | return (value) -> ExtSupplier.quiet(() -> doubleFunction.apply(value)).get(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.DoubleToIntFunction; 19 | 20 | public interface ExtDoubleToIntFunction { 21 | int applyAsInt(double value) throws E; 22 | 23 | static DoubleToIntFunction quiet(ExtDoubleToIntFunction doubleToIntFunction) { 24 | return (value) -> ExtIntSupplier.quiet(() -> doubleToIntFunction.applyAsInt(value)).getAsInt(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /config/src/test/java/com/facebook/config/MockJSONProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class MockJSONProvider implements JSONProvider { 22 | private final JSONObject jsonObject; 23 | 24 | public MockJSONProvider(JSONObject jsonObject) { 25 | this.jsonObject = jsonObject; 26 | } 27 | 28 | @Override 29 | public JSONObject get() throws JSONException { 30 | return jsonObject; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToLongBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToLongBiFunction; 19 | 20 | public interface ExtToLongBiFunction { 21 | long applyAsLong(T t, U u) throws E; 22 | 23 | static ToLongBiFunction quiet(ExtToLongBiFunction toLongBiFunction) { 24 | return (t, u) -> ExtLongSupplier.quiet(() -> toLongBiFunction.applyAsLong(t, u)).getAsLong(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/TestTimeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import org.joda.time.DateTimeZone; 19 | import org.testng.Assert; 20 | import org.testng.annotations.Test; 21 | 22 | public class TestTimeUtil { 23 | 24 | @Test(groups = "fast") 25 | public void testGetDateTimeZone() throws Exception { 26 | Assert.assertEquals(TimeUtil.getDateTimeZone(null), DateTimeZone.UTC); 27 | Assert.assertEquals(TimeUtil.getDateTimeZone(""), DateTimeZone.UTC); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/FunctionToMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | import com.google.common.base.Function; 19 | 20 | public class FunctionToMapper implements Mapper { 21 | private final Function function; 22 | 23 | public FunctionToMapper(Function function) { 24 | this.function = function; 25 | } 26 | 27 | @Override 28 | public Y map(X input) { 29 | return function.apply(input); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/ListMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import com.facebook.collectionsbase.Mapper; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class ListMapper { 23 | public static List map(List list, Mapper mapper) { 24 | List result = new ArrayList<>(); 25 | 26 | for (X item : list) { 27 | result.add(mapper.map(item)); 28 | } 29 | 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtObjIntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.function.ObjIntConsumer; 20 | 21 | public interface ExtObjIntConsumer { 22 | void accept(T t, int value) throws E; 23 | 24 | static ObjIntConsumer quiet(ExtObjIntConsumer objIntConsumer) { 25 | return (t, value) -> ExtRunnable.quiet(() -> objIntConsumer.accept(t, value)).run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToDoubleFunction; 19 | 20 | public interface ExtToDoubleFunction { 21 | double applyAsDouble(T value) throws E; 22 | 23 | static ToDoubleFunction quiet(ExtToDoubleFunction toDoubleFunction) { 24 | return (value) -> 25 | ExtDoubleSupplier.quiet(() -> toDoubleFunction.applyAsDouble(value)).getAsDouble(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/NullExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import com.facebook.util.exceptions.ExceptionHandler; 19 | 20 | /** 21 | * translates any exception to 'null'. Use only when you know the result won't be thrown 22 | * 23 | * @param 24 | */ 25 | public class NullExceptionHandler implements ExceptionHandler { 26 | @Override 27 | public T handle(S e) { 28 | return null; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.IntBinaryOperator; 19 | 20 | public interface ExtIntBinaryOperator { 21 | int applyAsInt(int left, int right) throws E; 22 | 23 | static IntBinaryOperator quiet(ExtIntBinaryOperator intBinaryOperator) { 24 | return (left, right) -> 25 | ExtIntSupplier.quiet(() -> intBinaryOperator.applyAsInt(left, right)).getAsInt(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/ClassExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class ClassExtractor implements Extractor> { 22 | @Override 23 | public Class extract(String key, JSONObject jsonObject) throws JSONException { 24 | try { 25 | return Class.forName(jsonObject.getString(key)); 26 | } catch (ClassNotFoundException e) { 27 | throw new JSONException(e); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.DoubleToLongFunction; 19 | 20 | public interface ExtDoubleToLongFunction { 21 | long applyAsLong(double value) throws E; 22 | 23 | static DoubleToLongFunction quiet(ExtDoubleToLongFunction doubleToLongFunction) { 24 | return (value) -> 25 | ExtLongSupplier.quiet(() -> doubleToLongFunction.applyAsLong(value)).getAsLong(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.IntToDoubleFunction; 19 | 20 | public interface ExtIntToDoubleFunction { 21 | double applyAsDouble(int value) throws E; 22 | 23 | static IntToDoubleFunction quiet(ExtIntToDoubleFunction intToDoubleFunction) { 24 | return (value) -> 25 | ExtDoubleSupplier.quiet(() -> intToDoubleFunction.applyAsDouble(value)).getAsDouble(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtObjLongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.function.ObjLongConsumer; 20 | 21 | public interface ExtObjLongConsumer { 22 | void accept(T t, long value) throws E; 23 | 24 | static ObjLongConsumer quiet(ExtObjLongConsumer objLongConsumer) { 25 | return (t, value) -> ExtRunnable.quiet(() -> objLongConsumer.accept(t, value)).run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrent-stats/README.md: -------------------------------------------------------------------------------- 1 | ## What is it? 2 | `jcommon-concurrent-stats` is an alternative stat implementation optimized for highly-concurrent 3 | updates. It trades increased memory usage for lower contention than the default implementation 4 | provided by `jcommon-stats`. 5 | 6 | The `Stats` class in `jcommon-stats` provides methods for creating both kinds: 7 | - `Stats.getRate("my-stat")`/`Stats.concurrentRate("my-concurrent-stat")` 8 | - `Stats.getSpread("my-stat")`/`Stats.concurrentSpread("my-concurrent-stat")` 9 | - `Stats.concurrentSpreadRate("my-concurrent-stat")` (cheaper than creating them separately) 10 | 11 | See the `RateStat` and `SpreadStat` JavaDocs for more details on their implementation and accuracy. 12 | 13 | ## What does it depend on? 14 | 15 | Nothing but built-in Java classes. 16 | 17 | Care was taken to avoid introducing any dependencies, so you can use these libraries with any 18 | existing code base without worry of dependency conflicts. (So if you submit any pull requests, 19 | please try not to introduce any new dependencies.) 20 | 21 | This is the only reason for a separate module. Otherwise, these classes would be part of 22 | `jcommon-stats`. 23 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/function/TestExtIntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.TestQuietFunctionBase; 19 | import java.util.function.Supplier; 20 | 21 | public class TestExtIntSupplier extends TestQuietFunctionBase { 22 | @Override 23 | protected void throwFromQuiet(Supplier toThrow) { 24 | ExtIntSupplier.quiet( 25 | () -> { 26 | throw toThrow.get(); 27 | }) 28 | .getAsInt(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /collections/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/subprocess/ProcessBuilderWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.subprocess; 17 | 18 | import java.io.File; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** Wrapper interface so that unit tests can stub ProcessBuilder. */ 23 | public interface ProcessBuilderWrapper { 24 | public Process createProcess( 25 | RedirectErrorsTo redirectErrorsTo, 26 | Map environmentOverrides, 27 | File workingDirectory, 28 | List command); 29 | } 30 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.LongBinaryOperator; 19 | 20 | public interface ExtLongBinaryOperator { 21 | long applyAsLong(long left, long right) throws E; 22 | 23 | static LongBinaryOperator quiet(ExtLongBinaryOperator longBinaryOperator) { 24 | return (left, right) -> 25 | ExtLongSupplier.quiet(() -> longBinaryOperator.applyAsLong(left, right)).getAsLong(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.LongToDoubleFunction; 19 | 20 | public interface ExtLongToDoubleFunction { 21 | double applyAsDouble(long value) throws E; 22 | 23 | static LongToDoubleFunction quiet(ExtLongToDoubleFunction longToDoubleFunction) { 24 | return (value) -> 25 | ExtDoubleSupplier.quiet(() -> longToDoubleFunction.applyAsDouble(value)).getAsDouble(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/function/TestExtLongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.TestQuietFunctionBase; 19 | import java.util.function.Supplier; 20 | 21 | public class TestExtLongSupplier extends TestQuietFunctionBase { 22 | @Override 23 | protected void throwFromQuiet(Supplier toThrow) { 24 | ExtLongSupplier.quiet( 25 | () -> { 26 | throw toThrow.get(); 27 | }) 28 | .getAsLong(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/SingletonExecutorServiceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.ExecutorService; 19 | 20 | public class SingletonExecutorServiceFactory 21 | implements ExecutorServiceFactory { 22 | private final T instance; 23 | 24 | public SingletonExecutorServiceFactory(T instance) { 25 | this.instance = instance; 26 | } 27 | 28 | @Override 29 | public T create() { 30 | return instance; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/StringExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | 21 | public class StringExtractor implements Extractor { 22 | @Override 23 | public String extract(String key, JSONObject jsonObject) throws JSONException { 24 | Object obj = jsonObject.get(key); 25 | 26 | if (obj instanceof String) { 27 | return (String) obj; 28 | } else { 29 | return String.valueOf(obj); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import org.apache.commons.lang.StringEscapeUtils; 19 | 20 | public class StringUtils { 21 | private StringUtils() { 22 | throw new AssertionError(); 23 | } 24 | 25 | public static String stripQuotes(String input) { 26 | if (input.startsWith("'") || input.startsWith("\"")) { 27 | return StringEscapeUtils.unescapeJava(input.substring(1, input.length() - 1)); 28 | } else { 29 | return input; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtObjDoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.function.ObjDoubleConsumer; 20 | 21 | public interface ExtObjDoubleConsumer { 22 | void accept(T t, double value) throws E; 23 | 24 | static ObjDoubleConsumer quiet(ExtObjDoubleConsumer objDoubleConsumer) { 25 | return (t, value) -> ExtRunnable.quiet(() -> objDoubleConsumer.accept(t, value)).run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtToDoubleBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.ToDoubleBiFunction; 19 | 20 | public interface ExtToDoubleBiFunction { 21 | double applyAsDouble(T t, U u) throws E; 22 | 23 | static ToDoubleBiFunction quiet(ExtToDoubleBiFunction toDoubleBiFunction) { 24 | return (t, u) -> 25 | ExtDoubleSupplier.quiet(() -> toDoubleBiFunction.applyAsDouble(t, u)).getAsDouble(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/function/TestExtBooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.TestQuietFunctionBase; 19 | import java.util.function.Supplier; 20 | 21 | public class TestExtBooleanSupplier extends TestQuietFunctionBase { 22 | @Override 23 | protected void throwFromQuiet(Supplier toThrow) { 24 | ExtBooleanSupplier.quiet( 25 | () -> { 26 | throw toThrow.get(); 27 | }) 28 | .getAsBoolean(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/function/TestExtDoubleSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.TestQuietFunctionBase; 19 | import java.util.function.Supplier; 20 | 21 | public class TestExtDoubleSupplier extends TestQuietFunctionBase { 22 | @Override 23 | protected void throwFromQuiet(Supplier toThrow) { 24 | ExtDoubleSupplier.quiet( 25 | () -> { 26 | throw toThrow.get(); 27 | }) 28 | .getAsDouble(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/EntryValueMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import com.facebook.collectionsbase.Mapper; 19 | import java.util.Map; 20 | import java.util.Map.Entry; 21 | 22 | /** 23 | * maps a Map.Entry to V 24 | * 25 | * @param key type of entry 26 | * @param value type of entry 27 | */ 28 | public class EntryValueMapper implements Mapper, V> { 29 | @Override 30 | public V map(Map.Entry input) { 31 | return input.getValue(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/digest/LongIdentityDigestFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.digest; 17 | 18 | /** 19 | * used when the value given as input has already been hashed (or otherwise sufficient randomized) 20 | * 21 | * @param 22 | */ 23 | public class LongIdentityDigestFunction implements DigestFunction { 24 | public static final LongIdentityDigestFunction INSTANCE = new LongIdentityDigestFunction(); 25 | 26 | @Override 27 | public long computeDigest(Long input) { 28 | return input; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/NamedDaemonThreadFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | /** A thread factory that marks all threads that it creates as daemon threads. */ 19 | public class NamedDaemonThreadFactory extends NamedThreadFactory { 20 | public NamedDaemonThreadFactory(String baseName) { 21 | super(baseName); 22 | } 23 | 24 | @Override 25 | public Thread newThread(Runnable r) { 26 | Thread thread = super.newThread(r); 27 | thread.setDaemon(true); 28 | return thread; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/serialization/Serializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.serialization; 17 | 18 | import java.io.DataOutput; 19 | 20 | /** 21 | * interface that takes an instance of T and typically will end up with a stream of bytes being 22 | * produced, depending on what DataInput is backed by.Implementations are often nested static 23 | * classes of Class\ in order to have access to private data 24 | */ 25 | public interface Serializer { 26 | public void serialize(T value, DataOutput out) throws SerDeException; 27 | } 28 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/FieldExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | /** 22 | * annotation for use with set() methods to indicate how to get a value from JSON to populate 23 | * the field via the set method 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface FieldExtractor { 27 | public String key(); 28 | 29 | public Class extractorClass(); 30 | 31 | public boolean optional() default false; 32 | } 33 | -------------------------------------------------------------------------------- /logging/src/jmh/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook.logging=INFO 32 | log4j.logger.org.apache.thrift=INFO -------------------------------------------------------------------------------- /logging/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /stats/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /testing/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /util/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /concurrency/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /lifecycle/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 Facebook, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=INFO,console 18 | 19 | # Logging Threshold 20 | log4j.threshhold=INFO 21 | 22 | # 23 | # console 24 | # Add "console" to rootlogger above if you want to use this 25 | # 26 | log4j.appender.console=org.apache.log4j.ConsoleAppender 27 | log4j.appender.console.target=System.err 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd}T%d{HH:mm:ss} %p %c{2}: %m%n 30 | 31 | log4j.logger.com.facebook=INFO 32 | log4j.logger.org.apache.thrift=INFO 33 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/RuntimeExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import com.facebook.util.exceptions.ExceptionHandler; 19 | 20 | /** map any exception to a runtime exception */ 21 | public class RuntimeExceptionHandler implements ExceptionHandler { 22 | public static final RuntimeExceptionHandler INSTANCE = new RuntimeExceptionHandler(); 23 | 24 | @Override 25 | public RuntimeException handle(S e) { 26 | return new RuntimeException(e.getMessage(), e); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import java.util.function.DoubleBinaryOperator; 19 | 20 | public interface ExtDoubleBinaryOperator { 21 | double applyAsDouble(double left, double right) throws E; 22 | 23 | static DoubleBinaryOperator quiet(ExtDoubleBinaryOperator doubleBinaryOperator) { 24 | return (left, right) -> 25 | ExtDoubleSupplier.quiet(() -> doubleBinaryOperator.applyAsDouble(left, right)) 26 | .getAsDouble(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/serialization/Deserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.serialization; 17 | 18 | import java.io.DataInput; 19 | 20 | /** 21 | * interface that takes a stream of bytes wrapped in the DataInput interface (to make reading 22 | * primitives easier), and builds a T. Implementations are often nested static classes of Class\ 23 | * in order to have access to specialized, private constructors 24 | * 25 | * @param 26 | */ 27 | public interface Deserializer { 28 | public T deserialize(DataInput in) throws SerDeException; 29 | } 30 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/CastingExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import com.facebook.util.exceptions.ExceptionHandler; 19 | 20 | /** 21 | * Performs a blind cast from an exception of type S to an exception of type T. NOTE: this should 22 | * only be used if S will always be of type T. 23 | * 24 | * @param 25 | */ 26 | public class CastingExceptionHandler implements ExceptionHandler { 27 | @Override 28 | public T handle(S e) { 29 | return (T) e; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/SnapshotProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | public interface SnapshotProvider { 19 | /** 20 | * Make the latest snapshot. 21 | * 22 | * @return the latest snapshot of T 23 | */ 24 | public T makeSnapshot(); 25 | 26 | /** 27 | * same as above, but the implementation may use alternative data structures to improve cpu 28 | * efficiency over memory since the caller is indicating this copy will be short-lived 29 | * 30 | * @return 31 | */ 32 | public T makeTransientSnapshot(); 33 | } 34 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/CriticalSectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import java.util.concurrent.atomic.AtomicBoolean; 19 | 20 | public class CriticalSectionFactory { 21 | private final AtomicBoolean isRunning = new AtomicBoolean(false); 22 | 23 | public Runnable wrap(Runnable runnable) { 24 | return () -> { 25 | if (isRunning.compareAndSet(false, true)) { 26 | try { 27 | runnable.run(); 28 | } finally { 29 | isRunning.set(false); 30 | } 31 | } 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/GaugeCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | /** Like an EventCounter but with additional functionality and additional overhead. */ 19 | public interface GaugeCounter extends EventCounterIf { 20 | /** Number of times add(long delta) has be called. */ 21 | public long getSamples(); 22 | 23 | /** Average value of delta for calls to add(long delta). */ 24 | public long getAverage(); 25 | 26 | /** Like add(delta) but used for merging with other GaugeCounters. */ 27 | public void add(long delta, long nsamples); 28 | } 29 | -------------------------------------------------------------------------------- /tools/src/test/java/com/facebook/tools/example/CheckpointManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.example; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | 20 | @SuppressWarnings("InterfaceNeverImplemented") 21 | @com.facebook.swift.service.ThriftService 22 | public interface CheckpointManager extends AutoCloseable { 23 | @ThriftMethod 24 | public String getCheckpoint(String application, String environment, int shard); 25 | 26 | @ThriftMethod 27 | public void deleteCheckpoint(String application, String environment, int shard); 28 | 29 | @Override 30 | void close(); 31 | } 32 | -------------------------------------------------------------------------------- /collections-foundation/src/main/java/com/facebook/collectionsbase/SafeFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collectionsbase; 17 | 18 | /** 19 | * the point of this is to restore the utility and equivalence of guava's "Function" in the case 20 | * that we have code that users our "Function". The only exception you can throw there or here is a 21 | * runtime. The parent, you can declare a checked exception which is useful. 22 | * 23 | * @param 24 | * @param 25 | */ 26 | public interface SafeFunction extends Function { 27 | @Override 28 | public V execute(K input); 29 | } 30 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/MaxEventCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import org.joda.time.ReadableDateTime; 19 | 20 | public class MaxEventCounter extends AssociativeAggregationCounter { 21 | public static final AssociativeAggregation AGGREGATION = (l1, l2) -> Math.max(l1, l2); 22 | 23 | public MaxEventCounter(ReadableDateTime start, ReadableDateTime end, long initialValue) { 24 | super(start, end, AGGREGATION, initialValue); 25 | } 26 | 27 | public MaxEventCounter(ReadableDateTime start, ReadableDateTime end) { 28 | this(start, end, Long.MIN_VALUE); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/MinEventCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import org.joda.time.ReadableDateTime; 19 | 20 | public class MinEventCounter extends AssociativeAggregationCounter { 21 | public static final AssociativeAggregation AGGREGATION = (l1, l2) -> Math.min(l1, l2); 22 | 23 | public MinEventCounter(ReadableDateTime start, ReadableDateTime end, long initialValue) { 24 | super(start, end, AGGREGATION, initialValue); 25 | } 26 | 27 | public MinEventCounter(ReadableDateTime start, ReadableDateTime end) { 28 | this(start, end, Long.MAX_VALUE); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/Status.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | interface Status { 19 | public void status(String line); 20 | 21 | public void status(boolean value); 22 | 23 | public void status(char value); 24 | 25 | public void status(int value); 26 | 27 | public void status(long value); 28 | 29 | public void status(float value); 30 | 31 | public void status(double value); 32 | 33 | public void status(char[] value); 34 | 35 | public void status(Object value); 36 | 37 | public void statusf(String format, Object... args); 38 | 39 | public void clearStatus(); 40 | } 41 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/SynchronizedSetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.SetFactory; 19 | import java.util.Collections; 20 | import java.util.Set; 21 | 22 | public class SynchronizedSetFactory implements SetFactory> { 23 | private final SetFactory> factory; 24 | 25 | public SynchronizedSetFactory(SetFactory> factory) { 26 | this.factory = factory; 27 | } 28 | 29 | @Override 30 | public Set create() { 31 | return Collections.synchronizedSet(factory.create()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/ExtSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import com.facebook.util.exceptions.UncheckedCheckedException; 19 | import java.util.function.Supplier; 20 | 21 | public interface ExtSupplier { 22 | T get() throws E; 23 | 24 | public static Supplier quiet(ExtSupplier supplier) { 25 | return () -> { 26 | try { 27 | return supplier.get(); 28 | } catch (Error | RuntimeException e) { 29 | throw e; 30 | } catch (Throwable e) { 31 | throw new UncheckedCheckedException(e); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/WrappedIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import java.util.Iterator; 19 | 20 | public class WrappedIterator implements Iterator { 21 | private final Iterator delegate; 22 | 23 | public WrappedIterator(Iterator delegate) { 24 | this.delegate = delegate; 25 | } 26 | 27 | @Override 28 | public boolean hasNext() { 29 | return delegate.hasNext(); 30 | } 31 | 32 | @Override 33 | public T next() { 34 | return delegate.next(); 35 | } 36 | 37 | @Override 38 | public void remove() { 39 | delegate.remove(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /stats/src/test/java/com/facebook/stats/TestingClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import java.util.concurrent.TimeUnit; 19 | 20 | public class TestingClock implements Clock { 21 | private long time; 22 | 23 | public TestingClock(long time) { 24 | this.time = time; 25 | } 26 | 27 | public TestingClock() { 28 | this(0); 29 | } 30 | 31 | @Override 32 | public long getMillis() { 33 | return time; 34 | } 35 | 36 | public void setTime(long millis) { 37 | time = millis; 38 | } 39 | 40 | public void increment(long delta, TimeUnit unit) { 41 | time += unit.toMillis(delta); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/SnapshotableSetImplFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.SetFactory; 19 | import java.util.Set; 20 | 21 | public class SnapshotableSetImplFactory implements SetFactory> { 22 | 23 | private final SetFactory> factory; 24 | 25 | public SnapshotableSetImplFactory(SetFactory> factory) { 26 | this.factory = factory; 27 | } 28 | 29 | @Override 30 | public SnapshotableSet create() { 31 | return new SnapshotableSetImpl<>(factory.create(), this); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/io/NullOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.io; 17 | 18 | import java.io.IOException; 19 | import java.io.OutputStream; 20 | 21 | class NullOutputStream extends OutputStream { 22 | public static final NullOutputStream INSTANCE = new NullOutputStream(); 23 | 24 | @Override 25 | public void write(int b) {} 26 | 27 | @Override 28 | public void write(byte[] b) {} 29 | 30 | @Override 31 | public void write(byte[] b, int off, int len) {} 32 | 33 | @Override 34 | public void flush() throws IOException {} 35 | 36 | @Override 37 | public void close() throws IOException {} 38 | } 39 | -------------------------------------------------------------------------------- /memory/src/main/java/com/facebook/memory/UnsafeAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.memory; 17 | 18 | import java.lang.reflect.Field; 19 | import sun.misc.Unsafe; 20 | 21 | public class UnsafeAccessor { 22 | private static Unsafe UNSAFE = null; 23 | 24 | static { 25 | try { 26 | Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); 27 | field.setAccessible(true); 28 | UnsafeAccessor.UNSAFE = (sun.misc.Unsafe) field.get(null); 29 | } catch (Exception e) { 30 | throw new AssertionError(e); 31 | } 32 | } 33 | 34 | public static Unsafe get() { 35 | return UnsafeAccessor.UNSAFE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/TranslatingIterable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections; 17 | 18 | import com.facebook.collectionsbase.Mapper; 19 | import java.util.Iterator; 20 | 21 | public class TranslatingIterable implements Iterable { 22 | private final Mapper mapper; 23 | private final Iterable iterable; 24 | 25 | public TranslatingIterable(Mapper mapper, Iterable iterable) { 26 | this.mapper = mapper; 27 | this.iterable = iterable; 28 | } 29 | 30 | @Override 31 | public Iterator iterator() { 32 | return new TranslatingIterator<>(mapper, iterable.iterator()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /stats/src/test/java/com/facebook/stats/TestHashBasedTopK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import com.facebook.logging.Logger; 19 | import com.facebook.logging.LoggerImpl; 20 | import com.facebook.stats.topk.HashBasedTopK; 21 | import com.facebook.stats.topk.TopK; 22 | 23 | public class TestHashBasedTopK extends TestIntegerTopK { 24 | private static final Logger LOG = LoggerImpl.getLogger(TestHashBasedTopK.class); 25 | 26 | @Override 27 | protected TopK getInstance(int keySpaceSize, int k) { 28 | return new HashBasedTopK(k); 29 | } 30 | 31 | @Override 32 | protected Logger getLogger() { 33 | return LOG; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /stats/src/test/java/com/facebook/stats/TestTreeBasedTopK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import com.facebook.logging.Logger; 19 | import com.facebook.logging.LoggerImpl; 20 | import com.facebook.stats.topk.TopK; 21 | import com.facebook.stats.topk.TreeBasedTopK; 22 | 23 | public class TestTreeBasedTopK extends TestIntegerTopK { 24 | private static final Logger LOG = LoggerImpl.getLogger(TestTreeBasedTopK.class); 25 | 26 | @Override 27 | protected TopK getInstance(int keySpaceSize, int k) { 28 | return new TreeBasedTopK(k); 29 | } 30 | 31 | @Override 32 | protected Logger getLogger() { 33 | return LOG; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.exceptions.UncheckedCheckedException; 19 | import java.util.function.IntSupplier; 20 | 21 | public interface ExtIntSupplier { 22 | int getAsInt() throws E; 23 | 24 | static IntSupplier quiet(ExtIntSupplier intSupplier) { 25 | return () -> { 26 | try { 27 | return intSupplier.getAsInt(); 28 | } catch (Error | RuntimeException e) { 29 | throw e; 30 | } catch (Throwable e) { 31 | throw new UncheckedCheckedException(e); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/ErrorLoggingRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | public class ErrorLoggingRunnable implements Runnable { 22 | private static final Logger LOG = LoggerFactory.getLogger(ErrorLoggingRunnable.class); 23 | private final Runnable delegate; 24 | 25 | public ErrorLoggingRunnable(Runnable delegate) { 26 | this.delegate = delegate; 27 | } 28 | 29 | @Override 30 | public void run() { 31 | try { 32 | delegate.run(); 33 | } catch (Throwable t) { 34 | LOG.error("error", t); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /stats/src/main/java/com/facebook/stats/FacebookStatsReporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import java.util.Map; 19 | 20 | /** A interface for reporting statistics (counters, exported values) */ 21 | public interface FacebookStatsReporter { 22 | 23 | void deleteCounter(String key); 24 | 25 | void resetCounter(String key); 26 | 27 | long incrementCounter(String key); 28 | 29 | long incrementCounter(String key, long increment); 30 | 31 | long setCounter(String key, long value); 32 | 33 | void setExportedValue(String key, String value); 34 | 35 | void removeExportedValue(String key); 36 | 37 | Map makeCounters(); 38 | } 39 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.exceptions.UncheckedCheckedException; 19 | import java.util.function.LongSupplier; 20 | 21 | public interface ExtLongSupplier { 22 | long getAsLong() throws E; 23 | 24 | static LongSupplier quiet(ExtLongSupplier longSupplier) { 25 | return () -> { 26 | try { 27 | return longSupplier.getAsLong(); 28 | } catch (Error | RuntimeException e) { 29 | throw e; 30 | } catch (Throwable e) { 31 | throw new UncheckedCheckedException(e); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /concurrency/src/test/java/com/facebook/concurrency/TestCaffeineConcurrentCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | public class TestCaffeineConcurrentCache extends AbstractTestConcurrentCache { 19 | @Override 20 | protected ConcurrentCache createCache( 21 | ValueFactory valueFactory) { 22 | return new CaffeineConcurrentCache<>(valueFactory, RuntimeExceptionHandler.INSTANCE); 23 | } 24 | 25 | @Override 26 | public void testRemoveBeforeValueSwap() throws Exception { 27 | // skip this test since ConcurrentHashMap.computeIfPresent(key, ...) will block remove(key) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.Objects; 20 | import java.util.function.Consumer; 21 | 22 | public interface ExtConsumer { 23 | void accept(T t) throws E; 24 | 25 | default ExtConsumer andThen(ExtConsumer after) { 26 | Objects.requireNonNull(after); 27 | return (t) -> { 28 | accept(t); 29 | after.accept(t); 30 | }; 31 | } 32 | 33 | static Consumer quiet(ExtConsumer consumer) { 34 | return (t) -> ExtRunnable.quiet(() -> consumer.accept(t)).run(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/EvictionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | /** 19 | * @param 20 | * @param 21 | */ 22 | public interface EvictionListener { 23 | /** 24 | * notifies a listener that a key/value pair has been evicted. No guarantee is made that the 25 | * key/value pair is not re-inserted by the time this occurs (ie, an eviction occurred in the 26 | * past) 27 | * 28 | * @param key key that was evicted 29 | * @param value value evicted. May be null in the case that either null was inserted, or an 30 | * exception was thrown producing the value 31 | */ 32 | void evicted(K key, V value); 33 | } 34 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/StreamImporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util; 17 | 18 | import java.io.BufferedReader; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.InputStreamReader; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | public class StreamImporter { 26 | public static List importLines(InputStream in) throws IOException { 27 | List lines = new ArrayList<>(); 28 | BufferedReader buffered = new BufferedReader(new InputStreamReader(in)); 29 | String line; 30 | while ((line = buffered.readLine()) != null) { 31 | lines.add(line); 32 | } 33 | return lines; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.exceptions.UncheckedCheckedException; 19 | import java.util.function.DoubleSupplier; 20 | 21 | public interface ExtDoubleSupplier { 22 | double getAsDouble() throws E; 23 | 24 | static DoubleSupplier quiet(ExtDoubleSupplier doubleSupplier) { 25 | return () -> { 26 | try { 27 | return doubleSupplier.getAsDouble(); 28 | } catch (Error | RuntimeException e) { 29 | throw e; 30 | } catch (Throwable e) { 31 | throw new UncheckedCheckedException(e); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tools/src/main/java/com/facebook/tools/parser/CliConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.tools.parser; 17 | 18 | import java.util.List; 19 | 20 | public interface CliConverter { 21 | public static CliConverter STRING = value -> value; 22 | public static CliConverter INT = value -> value == null ? null : Integer.parseInt(value); 23 | public static CliConverter> INT_LIST = new RangeListConverter(); 24 | public static CliConverter> LIST = new ListConverter<>(STRING); 25 | public static CliConverter BOOLEAN = 26 | value -> value == null ? null : Boolean.valueOf(value); 27 | 28 | public T convert(String value) throws Exception; 29 | } 30 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtBooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.exceptions.UncheckedCheckedException; 19 | import java.util.function.BooleanSupplier; 20 | 21 | public interface ExtBooleanSupplier { 22 | boolean getAsBoolean() throws E; 23 | 24 | static BooleanSupplier quiet(ExtBooleanSupplier booleanSupplier) { 25 | return () -> { 26 | try { 27 | return booleanSupplier.getAsBoolean(); 28 | } catch (Error | RuntimeException e) { 29 | throw e; 30 | } catch (Throwable e) { 31 | throw new UncheckedCheckedException(e); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtIntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.Objects; 20 | import java.util.function.IntConsumer; 21 | 22 | public interface ExtIntConsumer { 23 | void accept(int value) throws E; 24 | 25 | default ExtIntConsumer andThen(ExtIntConsumer after) { 26 | Objects.requireNonNull(after); 27 | return (t) -> { 28 | accept(t); 29 | after.accept(t); 30 | }; 31 | } 32 | 33 | static IntConsumer quiet(ExtIntConsumer intConsumer) { 34 | return (value) -> ExtRunnable.quiet(() -> intConsumer.accept(value)).run(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/serialization/SerDeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.serialization; 17 | 18 | public class SerDeException extends Exception { 19 | public SerDeException() {} 20 | 21 | public SerDeException(String message) { 22 | super(message); 23 | } 24 | 25 | public SerDeException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | 29 | public SerDeException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public SerDeException( 34 | String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 35 | super(message, cause, enableSuppression, writableStackTrace); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /stats/src/test/java/com/facebook/stats/TestTreeBasedIntegerTopK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import com.facebook.logging.Logger; 19 | import com.facebook.logging.LoggerImpl; 20 | import com.facebook.stats.topk.TopK; 21 | import com.facebook.stats.topk.TreeBasedIntegerTopK; 22 | 23 | public class TestTreeBasedIntegerTopK extends TestIntegerTopK { 24 | private static final Logger LOG = LoggerImpl.getLogger(TestTreeBasedIntegerTopK.class); 25 | 26 | @Override 27 | protected TopK getInstance(int keySpaceSize, int k) { 28 | return new TreeBasedIntegerTopK(keySpaceSize, k); 29 | } 30 | 31 | @Override 32 | protected Logger getLogger() { 33 | return LOG; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to jcommon 2 | 3 | ## Our Development Process 4 | 5 | jcommon is primarily developed internally at Facebook, where 6 | an automated process occasionally pushes changes to GitHub. 7 | 8 | ## Pull Requests 9 | 10 | To submit a pull request: 11 | 12 | 1. Fork the repo and create your branch from `master`. 13 | 2. If you've added code that should be tested, add tests. 14 | 3. If you've changed APIs, update the documentation. 15 | 4. Ensure the test suite passes. 16 | 5. Make sure your code lints. 17 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 18 | 19 | Pull requests are not regularly reviewed. 20 | 21 | ## Contributor License Agreement ("CLA") 22 | 23 | In order to accept your pull request, we need you to submit a CLA. You only need 24 | to do this once to work on any of Facebook's open source projects. 25 | 26 | Complete your CLA here: 27 | 28 | ## Issues 29 | 30 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 31 | disclosure of security bugs. In those cases, please go through the process 32 | outlined on that page and do not file a public issue. 33 | 34 | ## License 35 | 36 | By contributing to jcommon, you agree that your contributions will be licensed 37 | under the LICENSE file in the root directory of this source tree. 38 | -------------------------------------------------------------------------------- /stats/src/test/java/com/facebook/stats/TestArrayBasedIntegerTopK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.stats; 17 | 18 | import com.facebook.logging.Logger; 19 | import com.facebook.logging.LoggerImpl; 20 | import com.facebook.stats.topk.ArrayBasedIntegerTopK; 21 | import com.facebook.stats.topk.TopK; 22 | 23 | public class TestArrayBasedIntegerTopK extends TestIntegerTopK { 24 | private static final Logger LOG = LoggerImpl.getLogger(TestArrayBasedIntegerTopK.class); 25 | 26 | @Override 27 | protected TopK getInstance(int keySpaceSize, int k) { 28 | return new ArrayBasedIntegerTopK(keySpaceSize, k); 29 | } 30 | 31 | @Override 32 | protected Logger getLogger() { 33 | return LOG; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /util/src/test/java/com/facebook/util/digest/TestLongMurmur3Hash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.digest; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.Test; 20 | 21 | public class TestLongMurmur3Hash { 22 | 23 | @Test(groups = "fast") 24 | public void testConsistency() throws Exception { 25 | LongMurmur3Hash longMurmur3Hash1 = new LongMurmur3Hash(); 26 | LongMurmur3Hash longMurmur3Hash2 = new LongMurmur3Hash(); 27 | 28 | for (long i = 0; i < 1000; i++) { 29 | Assert.assertEquals( 30 | longMurmur3Hash1.computeDigest(i), 31 | longMurmur3Hash2.computeDigest(i), 32 | String.format("Hashes don't match for %d", i)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /concurrency/src/main/java/com/facebook/concurrency/CallableSnapshotFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.concurrency; 17 | 18 | /** 19 | * This is very similar to a factory, but the apply() function implementations usually create a 20 | * Callable which is then executed. The resuting value, or exception, is then stored in the 21 | * CallableSnapshot 22 | * 23 | * @param type of the input to pass to underlying implementation. Used in creating the Callable 24 | * @param output of the implementation's Callable 25 | * @param exception type that may be thrown by the Callable 26 | */ 27 | public interface CallableSnapshotFunction { 28 | CallableSnapshot apply(I input); 29 | } 30 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtSupplier; 19 | import java.util.Objects; 20 | import java.util.function.BiFunction; 21 | 22 | public interface ExtBiFunction { 23 | R apply(T t, U u) throws E; 24 | 25 | default ExtBiFunction andThen(ExtFunction after) { 26 | Objects.requireNonNull(after); 27 | return (t, u) -> after.apply(apply(t, u)); 28 | } 29 | 30 | static BiFunction quiet(ExtBiFunction biFunction) { 31 | return (t, u) -> ExtSupplier.quiet(() -> biFunction.apply(t, u)).get(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtDoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.Objects; 20 | import java.util.function.DoubleConsumer; 21 | 22 | public interface ExtDoubleConsumer { 23 | void accept(double value); 24 | 25 | default ExtDoubleConsumer andThen(ExtDoubleConsumer after) { 26 | Objects.requireNonNull(after); 27 | return (t) -> { 28 | accept(t); 29 | after.accept(t); 30 | }; 31 | } 32 | 33 | static DoubleConsumer quiet(ExtDoubleConsumer doubleConsumer) { 34 | return (value) -> ExtRunnable.quiet(() -> doubleConsumer.accept(value)).run(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /util/src/main/java/com/facebook/util/function/ExtLongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.util.function; 17 | 18 | import com.facebook.util.ExtRunnable; 19 | import java.util.Objects; 20 | import java.util.function.LongConsumer; 21 | 22 | public interface ExtLongConsumer { 23 | void accept(long value) throws E; 24 | 25 | default ExtLongConsumer andThen(ExtLongConsumer after) { 26 | Objects.requireNonNull(after); 27 | return (value) -> { 28 | accept(value); 29 | after.accept(value); 30 | }; 31 | } 32 | 33 | static LongConsumer quiet(ExtLongConsumer longConsumer) { 34 | return (value) -> ExtRunnable.quiet(() -> longConsumer.accept(value)).run(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /collections/src/main/java/com/facebook/collections/specialized/MutableByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.collections.specialized; 17 | 18 | import com.facebook.collections.ByteArray; 19 | import java.io.ByteArrayOutputStream; 20 | 21 | /** allows direct access to the underlying buffer without a copy also has a higher default size */ 22 | public class MutableByteArrayOutputStream extends ByteArrayOutputStream { 23 | 24 | public MutableByteArrayOutputStream() { 25 | // use a higher default size 26 | this(1024); 27 | } 28 | 29 | public MutableByteArrayOutputStream(int size) { 30 | super(size); 31 | } 32 | 33 | public ByteArray getBytes() { 34 | return ByteArray.wrap(buf, 0, size()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /config/src/main/java/com/facebook/config/dynamic/Option.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.facebook.config.dynamic; 17 | 18 | public interface Option { 19 | public V getValue(); 20 | 21 | public void setValue(V value); 22 | 23 | /** 24 | * Registers a new watcher for this property. If the watcher is already watching this property, 25 | * this method does nothing. 26 | * 27 | * @param watcher a property watcher 28 | */ 29 | public void addWatcher(OptionWatcher watcher); 30 | 31 | /** 32 | * Unregisters a watcher. If the watcher is not already watching this property, this method does 33 | * nothing. 34 | * 35 | * @param watcher a property watcher 36 | */ 37 | public void removeWatcher(OptionWatcher watcher); 38 | } 39 | --------------------------------------------------------------------------------