diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryTopologySnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryTopologySnapshot.java deleted file mode 100644 index d2ad0d2104682..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryTopologySnapshot.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.managers.discovery; - -import java.util.Collection; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -import org.apache.ignite.internal.util.typedef.internal.S; - -/** - * Topology snapshot managed by discovery manager. - */ -public class GridDiscoveryTopologySnapshot { - /** Topology version. */ - private long topVer; - - /** Topology nodes. */ - @GridToStringInclude - private Collection topNodes; - - /** - * Creates a topology snapshot with given topology version and topology nodes. - * - * @param topVer Topology version. - * @param topNodes Topology nodes. - */ - public GridDiscoveryTopologySnapshot(long topVer, Collection topNodes) { - this.topVer = topVer; - this.topNodes = topNodes; - } - - /** - * Gets topology version if this event is raised on - * topology change and configured discovery SPI implementation - * supports topology versioning. - * - * @return Topology version or {@code 0} if configured discovery SPI implementation - * does not support versioning. - */ - public long topologyVersion() { - return topVer; - } - - /** - * Gets topology nodes from topology snapshot. If SPI implementation does not support - * versioning, the best effort snapshot will be captured. - * - * @return Topology snapshot. - */ - public Collection topologyNodes() { - return topNodes; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridDiscoveryTopologySnapshot.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePeekModes.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePeekModes.java deleted file mode 100644 index 4ab3a15c84f64..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePeekModes.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache; - -import org.apache.ignite.cache.CachePeekMode; - -/** - * - */ -public class CachePeekModes { - /** */ - public static final CachePeekMode[] ONHEAP_ONLY = {CachePeekMode.ONHEAP}; -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RecoveryDebug.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RecoveryDebug.java deleted file mode 100644 index c68d1cfcd612d..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RecoveryDebug.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.persistence; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.file.Paths; -import java.time.Instant; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.EnumSet; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.internal.pagemem.wal.record.DataEntry; -import org.apache.ignite.internal.pagemem.wal.record.DataRecord; -import org.apache.ignite.internal.pagemem.wal.record.TxRecord; -import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.jetbrains.annotations.Nullable; - -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.READ; -import static java.nio.file.StandardOpenOption.WRITE; - -/** - * - */ -public class RecoveryDebug implements AutoCloseable { - /** */ - private static final DateTimeFormatter DATE_FORMATTER = - DateTimeFormatter.ofPattern("dd-MM-yyyy-HH-mm-ss-SSS").withZone(ZoneId.of("UTC")); - - /** */ - @Nullable private final IgniteLogger log; - - /** */ - @Nullable private FileChannel fc; - - /** - * @param constId Consistent ID. - */ - public RecoveryDebug(Object constId, long time) { - this(constId, time, null); - } - - /** - * @param constId Consistent ID. - * @param log Logger. - */ - public RecoveryDebug(Object constId, long time, @Nullable IgniteLogger log) { - this.log = log; - - try { - String workDir = U.defaultWorkDirectory(); - - File tmpDir = new File(workDir, "tmp"); - - if (!tmpDir.exists()) - if (!tmpDir.mkdir()) - return; - - File f = new File(tmpDir, "recovery-" + - DATE_FORMATTER.format(Instant.ofEpochMilli(time)) + "-" + constId + ".log"); - - f.createNewFile(); - - fc = FileChannel.open(Paths.get(f.getPath()), EnumSet.of(CREATE, READ, WRITE)); - } - catch (IgniteCheckedException | IOException e) { - U.error(log, "Fail create recovery debug file.", e); - - fc = null; - } - } - - /** - * @param rec TX record to append. - * @return {@code this} for convenience. - */ - public RecoveryDebug append(TxRecord rec) { - GridCacheVersion txVer = rec.nearXidVersion(); - - return fc == null ? this : appendFile( - "Tx record " + rec.state() + " " + rec.nearXidVersion() + " timestamp " + rec.timestamp() - ); - } - - /** - * @param rec Data record to append. - * @param unwrapKeyValue unwrap key and value flag. - * @return {@code this} for convenience. - */ - public RecoveryDebug append(DataRecord rec, boolean unwrapKeyValue) { - if (fc == null) - return this; - - append("Data record\n"); - - int entryCnt = rec.entryCount(); - - for (int i = 0; i < entryCnt; i++) { - DataEntry dataEntry = rec.get(i); - - append("\t" + dataEntry.op() + " " + dataEntry.nearXidVersion() + - (unwrapKeyValue ? " " + dataEntry.key() + " " + dataEntry.value() : "") + "\n" - ); - } - - return this; - } - - /** - * @param st Statement to append. - * @return {@code this} for convenience. - */ - public RecoveryDebug append(Object st) { - return fc == null ? this : appendFile(st); - } - - /** - * @param st Statement to append. - * @return {@code this} for convenience. - */ - private RecoveryDebug appendFile(Object st) { - try { - fc.write(ByteBuffer.wrap(st.toString().getBytes())); - } - catch (IOException e) { - U.error(null, "Fail write to recovery dump file.", e); - } - - return this; - } - - /** - * Closes this debug insrance. - */ - @Override public void close() { - if (fc != null) { - try { - fc.force(true); - - fc.close(); - } - catch (IOException e) { - U.error(null, "Fail close recovery dump file.", e); - } - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloader.java deleted file mode 100644 index 2678315fe03ea..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloader.java +++ /dev/null @@ -1,225 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package org.apache.ignite.internal.processors.cache.persistence.file; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.channels.FileChannel; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.typedef.internal.U; - -/** - * Part of direct node to node file downloading - */ -public class FileDownloader { - /** */ - private final IgniteLogger log; - - /** */ - private static final int CHUNK_SIZE = 16 * 1024 * 1024; - - /** */ - private final Path path; - - /** */ - private long bytesReceived; - - /** */ - private boolean doneTransfer; - - /** */ - private long bytesSent = -1; - - /** */ - private ServerSocketChannel srvChan; - - /** */ - private SocketChannel readChan; - - /** */ - private final GridFutureAdapter finishFut = new GridFutureAdapter<>(); - - /** - * - */ - public FileDownloader(IgniteLogger log, Path path) { - this.log = log; - this.path = path; - } - - /** - * @return Download finish future. - */ - public IgniteInternalFuture finishFuture() { - return finishFut; - } - - /** - * - */ - public InetSocketAddress start() throws IgniteCheckedException { - try { - ServerSocketChannel ch = ServerSocketChannel.open(); - - ch.bind(null); - - srvChan = ch; - - return (InetSocketAddress)ch.getLocalAddress(); - } - catch (Exception ex) { - throw new IgniteCheckedException(ex); - } - } - - /** - * - */ - public void download() { - FileChannel writeChan = null; - SocketChannel readChan = null; - - try { - File f = new File(path.toUri().getPath()); - - if (f.exists()) - f.delete(); - - File cacheWorkDir = f.getParentFile(); - - if (!cacheWorkDir.exists()) - cacheWorkDir.mkdir(); - - readChan = srvChan.accept(); - - if (log != null && log.isInfoEnabled()) - log.info("Accepted incoming connection, closing server socket: " + srvChan.getLocalAddress()); - - U.closeQuiet(srvChan); - - synchronized (this) { - if (finishFut.isDone()) { - // Already received a response with error. - U.closeQuiet(readChan); - - return; - } - else - this.readChan = readChan; - } - - writeChan = FileChannel.open(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE); - - if (log != null && log.isInfoEnabled()) - log.info("Started writing file [path=" + path + ", rmtAddr=" + readChan.getRemoteAddress() + ']'); - - long pos = 0; - - boolean finish = false; - - while (!finish && !finishFut.isDone()) { - long transferred = writeChan.transferFrom(readChan, pos, CHUNK_SIZE); - - pos += transferred; - - finish = onBytesReceived(transferred); - } - } - catch (IOException ex) { - finishFut.onDone(ex); - } - finally { - try { - onDoneTransfer(); - } - finally { - // Safety. - U.closeQuiet(srvChan); - U.close(writeChan, log); - U.close(readChan, log); - } - } - } - - /** - * - */ - public void onResult(long size, Throwable th) { - synchronized (this) { - if (th != null) { - bytesSent = 0; - - finishFut.onDone(th); - - U.closeQuiet(readChan); - } - else { - bytesSent = size; - - checkCompleted(); - } - } - } - - /** - * @param transferred Number of bytes transferred. - * @return {@code True} if should keep reading. - */ - private boolean onBytesReceived(long transferred) { - synchronized (this) { - bytesReceived += transferred; - - return bytesSent != -1 && bytesSent == bytesReceived; - } - } - - /** - * Called when reading thread stopped transferring bytes for any reason. - */ - private void onDoneTransfer() { - synchronized (this) { - doneTransfer = true; - - checkCompleted(); - } - } - - /** - * - */ - private void checkCompleted() { - // Compare sizes if done reading from the socket and received response from remote node. - if (doneTransfer && bytesSent != -1) { - if (bytesReceived == bytesSent) - finishFut.onDone(); - else { - finishFut.onDone(new IgniteException("Failed to transfer file (sent and received sizes mismatch) [" + - "bytesReceived=" + bytesReceived + ", bytesSent=" + bytesSent + ", file=" + path + ']')); - } - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileUploader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileUploader.java deleted file mode 100644 index 4ea4c06a24005..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FileUploader.java +++ /dev/null @@ -1,94 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package org.apache.ignite.internal.processors.cache.persistence.file; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.nio.channels.SocketChannel; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.typedef.internal.U; - -/** - * Part of direct node to node file downloading - */ -public class FileUploader { - /** */ - private static final int CHUNK_SIZE = 1024 * 1024; - - /** */ - private final Path path; - - /** */ - private final IgniteLogger log; - - /** - * - */ - public FileUploader(Path path, IgniteLogger log) { - this.path = path; - this.log = log; - } - - /** - * - */ - public void upload(SocketChannel writeChan, GridFutureAdapter finishFut) { - FileChannel readChan = null; - - try { - File file = new File(path.toUri().getPath()); - - if (!file.exists()) { - finishFut.onDone( - new IgniteCheckedException( - new FileNotFoundException(file.getAbsolutePath()) - ) - ); - - return; - } - - readChan = FileChannel.open(path, StandardOpenOption.READ); - - long written = 0; - - long size = readChan.size(); - - while (written < size) - written += readChan.transferTo(written, CHUNK_SIZE, writeChan); - - writeChan.shutdownOutput(); - writeChan.shutdownInput(); - - finishFut.onDone(written); - } - catch (IOException ex) { - finishFut.onDone(ex); - } - finally { - U.close(writeChan, log); - U.close(readChan, log); - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/UnzipFileIOFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/UnzipFileIOFactory.java deleted file mode 100644 index 674ba29194914..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/UnzipFileIOFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.persistence.file; - -import java.io.File; -import java.io.IOException; -import java.nio.file.OpenOption; - -/** - * File I/O factory which provides {@link UnzipFileIO} implementation of FileIO. - */ -public class UnzipFileIOFactory implements FileIOFactory { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public UnzipFileIO create(File file, OpenOption... modes) throws IOException { - return new UnzipFileIO(file); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/partstate/PartitionRecoverState.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/partstate/PartitionRecoverState.java deleted file mode 100644 index 4c7e4d7323011..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/partstate/PartitionRecoverState.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.persistence.partstate; - -/** - * Class holds state of partition during recovery process. - */ -public class PartitionRecoverState { - /** State id. */ - private final int stateId; - - /** Update counter. */ - private final long updateCounter; - - /** - * @param stateId State id. - * @param updateCounter Update counter. - */ - public PartitionRecoverState(int stateId, long updateCounter) { - this.stateId = stateId; - this.updateCounter = updateCounter; - } - - /** - * - */ - public int stateId() { - return stateId; - } - - /** - * - */ - public long updateCounter() { - return updateCounter; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceSupplierInjector.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceSupplierInjector.java deleted file mode 100644 index 679303b80660d..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceSupplierInjector.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.resource; - -import java.util.function.Supplier; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.managers.deployment.GridDeployment; -import org.apache.ignite.internal.util.typedef.internal.S; - -/** - * Simple injector which wraps resource object supplier. - * - * @param Type of injected resource. - */ -class GridResourceSupplierInjector implements GridResourceInjector { - /** Resource to inject. */ - private final Supplier supplier; - - /** - * Creates injector. - * - * @param supplier Resource supplier. - */ - GridResourceSupplierInjector(Supplier supplier) { - this.supplier = supplier; - } - - /** {@inheritDoc} */ - @Override public void inject(GridResourceField field, Object target, Class depCls, GridDeployment dep) - throws IgniteCheckedException { - GridResourceUtils.inject(field.getField(), target, supplier.get()); - } - - /** {@inheritDoc} */ - @Override public void inject(GridResourceMethod mtd, Object target, Class depCls, GridDeployment dep) - throws IgniteCheckedException { - GridResourceUtils.inject(mtd.getMethod(), target, supplier.get()); - } - - /** {@inheritDoc} */ - @Override public void undeploy(GridDeployment dep) { - /* No-op. There is no cache. */ - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridResourceSupplierInjector.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridCloseableIteratorAdapterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridCloseableIteratorAdapterEx.java deleted file mode 100644 index b5c7d1fcad082..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridCloseableIteratorAdapterEx.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.util.NoSuchElementException; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.util.lang.GridCloseableIterator; -import org.apache.ignite.internal.util.lang.GridIteratorAdapter; - -/** - * Adapter for closeable iterator that can be safely closed concurrently. - */ -public abstract class GridCloseableIteratorAdapterEx extends GridIteratorAdapter - implements GridCloseableIterator { - /** */ - private static final long serialVersionUID = 0L; - - /** Closed flag. */ - private final AtomicBoolean closed = new AtomicBoolean(); - - /** {@inheritDoc} */ - @Override public final T nextX() throws IgniteCheckedException { - if (closed.get()) - return null; - - try { - if (!onHasNext()) - throw new NoSuchElementException(); - - return onNext(); - } - catch (IgniteCheckedException e) { - if (closed.get()) - return null; - else - throw e; - } - } - - /** - * @return Next element. - * @throws IgniteCheckedException If failed. - * @throws NoSuchElementException If no element found. - */ - protected abstract T onNext() throws IgniteCheckedException; - - /** {@inheritDoc} */ - @Override public final boolean hasNextX() throws IgniteCheckedException { - if (closed.get()) - return false; - - try { - return onHasNext(); - } - catch (IgniteCheckedException e) { - if (closed.get()) - return false; - else - throw e; - } - } - - /** - * @return {@code True} if iterator has next element. - * @throws IgniteCheckedException If failed. - */ - protected abstract boolean onHasNext() throws IgniteCheckedException; - - /** {@inheritDoc} */ - @Override public final void removeX() throws IgniteCheckedException { - if (closed.get()) - throw new NoSuchElementException("Iterator has been closed."); - - try { - onRemove(); - } - catch (IgniteCheckedException e) { - if (!closed.get()) - throw e; - } - } - - /** - * Called on remove from iterator. - * - * @throws IgniteCheckedException If failed. - */ - protected void onRemove() throws IgniteCheckedException { - throw new UnsupportedOperationException("Remove is not supported."); - } - - /** {@inheritDoc} */ - @Override public final void close() throws IgniteCheckedException { - if (closed.compareAndSet(false, true)) - onClose(); - } - - /** - * Invoked on iterator close. - * - * @throws IgniteCheckedException If closing failed. - */ - protected void onClose() throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public boolean isClosed() { - return closed.get(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridCollections.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridCollections.java deleted file mode 100644 index b7ee109c880ec..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridCollections.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -/** - * Provides locked wrappers around given maps and collections. Since {@link ReentrantLock} - * performs a lot better than standard Java {@code synchronization}, these locked wrappers - * should perform better as their analogous methods in {@code java.util.Collections} class. - */ -public final class GridCollections { - /** - * Ensure singleton. - */ - private GridCollections() { - // No-op. - } - - /** - * Gets locked map wrapping given map. - * - * @param m Map to wrap into locked implementation. - * @return Locked map. - */ - public static Map lockedMap(Map m) { - return new LockedMap<>(m); - } - - /** - * Gets locked set wrapping given set. - * - * @param s Set to wrap into locked implementation. - * @return Locked set. - */ - public static Set lockedSet(Set s) { - return new LockedSet<>(s); - } - - /** - * Gets locked collection wrapping given set. - * - * @param c Collection to wrap into locked implementation. - * @return Locked collection. - */ - public static Collection lockedCollection(Collection c) { - return new LockedCollection<>(c); - } - - /** - * Synchronized map. - */ - private static final class LockedMap extends ReentrantLock implements Map { - /** */ - private static final long serialVersionUID = 0L; - - /** Delegate map. */ - private final Map m; - - /** - * @param m Map. - */ - private LockedMap(Map m) { - this.m = m; - } - - /** {@inheritDoc} */ - @Override public void clear() { - lock(); - - try { - m.clear(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int size() { - lock(); - - try { - return m.size(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean isEmpty() { - lock(); - - try { - return m.isEmpty(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean containsKey(Object key) { - lock(); - - try { - return m.containsKey(key); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean containsValue(Object val) { - lock(); - - try { - return m.containsValue(val); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public V get(Object key) { - lock(); - - try { - return m.get(key); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public V put(K key, V val) { - lock(); - - try { - return m.put(key, val); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public V remove(Object key) { - lock(); - - try { - return m.remove(key); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public void putAll(Map m) { - lock(); - - try { - this.m.putAll(m); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public Set keySet() { - lock(); - - try { - return new LockedSet<>(m.keySet()); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public Collection values() { - lock(); - - try { - return new LockedCollection<>(m.values()); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public Set> entrySet() { - lock(); - - try { - return new LockedSet<>(m.entrySet()); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - lock(); - - try { - return m.equals(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - lock(); - - try { - return m.hashCode(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - lock(); - - try { - return m.toString(); - } - finally { - unlock(); - } - } - - /** - * Overrides write object. - * - * @param s Object output stream. - * @throws IOException If failed. - */ - private void writeObject(ObjectOutputStream s) throws IOException { - lock(); - - try { - s.defaultWriteObject(); - } - finally { - unlock(); - } - } - } - - /** - * Synchronized set. - */ - private static final class LockedSet extends LockedCollection implements Set { - /** */ - private static final long serialVersionUID = 0L; - - /** - * @param s Set to wrap. - */ - @SuppressWarnings({"TypeMayBeWeakened"}) - private LockedSet(Set s) { - super(s); - } - } - - /** - * Synchronized list. - */ - private static final class LockedList extends LockedCollection implements List { - /** */ - private static final long serialVersionUID = 0L; - - /** List. */ - private final List l; - - /** - * @param l List to wrap. - */ - private LockedList(List l) { - super(l); - - this.l = l; - } - - /** {@inheritDoc} */ - @Override public void add(int index, E e) { - lock(); - - try { - l.add(index, e); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean addAll(int idx, Collection c) { - lock(); - - try { - return l.addAll(c); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public E get(int idx) { - lock(); - - try { - return l.get(idx); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public E set(int idx, E e) { - lock(); - - try { - return l.set(idx, e); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public E remove(int idx) { - lock(); - - try { - return l.remove(idx); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int indexOf(Object o) { - lock(); - - try { - return l.indexOf(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int lastIndexOf(Object o) { - lock(); - - try { - return l.lastIndexOf(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public ListIterator listIterator() { - return l.listIterator(); // Must be synchronized manually by user. - } - - /** {@inheritDoc} */ - @Override public ListIterator listIterator(int idx) { - return l.listIterator(idx); // Must be synchronized manually by user. - } - - /** {@inheritDoc} */ - @Override public List subList(int fromIdx, int toIdx) { - lock(); - - try { - return new LockedList<>(l.subList(fromIdx, toIdx)); - } - finally { - unlock(); - } - } - } - - /** - * Synchronized collection. - */ - private static class LockedCollection extends ReentrantLock implements Collection { - /** */ - private static final long serialVersionUID = 0L; - - /** Delegating collection. */ - protected final Collection c; - - /** - * @param c Delegating collection. - */ - private LockedCollection(Collection c) { - this.c = c; - } - - /** {@inheritDoc} */ - @Override public boolean add(E e) { - lock(); - - try { - return c.add(e); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int size() { - lock(); - - try { - return c.size(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean isEmpty() { - lock(); - - try { - return c.isEmpty(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean contains(Object o) { - lock(); - - try { - return c.contains(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public Iterator iterator() { - return c.iterator(); // Must be manually synced by user. - } - - /** {@inheritDoc} */ - @Override public Object[] toArray() { - lock(); - - try { - return c.toArray(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings({"SuspiciousToArrayCall"}) - @Override public T[] toArray(T[] a) { - lock(); - - try { - return c.toArray(a); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean remove(Object o) { - lock(); - - try { - return c.remove(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean containsAll(Collection c) { - lock(); - - try { - return this.c.containsAll(c); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean addAll(Collection c) { - lock(); - - try { - return this.c.addAll(c); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean removeAll(Collection c) { - lock(); - - try { - return this.c.removeAll(c); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean retainAll(Collection c) { - lock(); - - try { - return this.c.retainAll(c); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public void clear() { - lock(); - - try { - c.clear(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - lock(); - - try { - return c.hashCode(); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - lock(); - - try { - return c.equals(o); - } - finally { - unlock(); - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - lock(); - - try { - return c.toString(); - } - finally { - unlock(); - } - } - - /** - * Overrides write object. - * - * @param s Object output stream. - * @throws IOException If failed. - */ - private void writeObject(ObjectOutputStream s) throws IOException { - lock(); - - try { - s.defaultWriteObject(); - } - finally { - unlock(); - } - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridConcurrentPhantomHashSet.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridConcurrentPhantomHashSet.java deleted file mode 100644 index 642ddaa98fcd4..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridConcurrentPhantomHashSet.java +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.lang.ref.PhantomReference; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.NoSuchElementException; -import java.util.Set; -import org.apache.ignite.internal.util.tostring.GridToStringExclude; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.A; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.lang.IgniteClosure; -import org.jetbrains.annotations.Nullable; - -/** - * Concurrent phantom hash set implementation. - */ -public class GridConcurrentPhantomHashSet implements Set { - /** Empty array. */ - private static final Object[] EMPTY_ARR = new Object[0]; - - /** Reference store. */ - @GridToStringInclude - private GridConcurrentHashSet> store; - - /** Reference queue. */ - @GridToStringExclude - private final ReferenceQueue refQ = new ReferenceQueue<>(); - - /** Reference factory. */ - private final IgniteClosure> fact = new IgniteClosure>() { - @Override public PhantomReferenceElement apply(E e) { - assert e != null; - - return new PhantomReferenceElement<>(e, refQ); - } - }; - - /** - * Creates a new, empty set with a default initial capacity, - * load factor, and concurrencyLevel. - */ - public GridConcurrentPhantomHashSet() { - store = new GridConcurrentHashSet<>(); - } - - /** - * Creates a new, empty set with the specified initial - * capacity, and with default load factor and concurrencyLevel. - * - * @param initCap The initial capacity. The implementation - * performs internal sizing to accommodate this many elements. - * @throws IllegalArgumentException if the initial capacity of - * elements is negative. - */ - public GridConcurrentPhantomHashSet(int initCap) { - store = new GridConcurrentHashSet<>(initCap); - } - - /** - * Creates a new, empty set with the specified initial - * capacity, load factor, and concurrency level. - * - * @param initCap The initial capacity. The implementation - * performs internal sizing to accommodate this many elements. - * @param loadFactor The load factor threshold, used to control resizing. - * Resizing may be performed when the average number of elements per - * bin exceeds this threshold. - * @param conLevel The estimated number of concurrently - * updating threads. The implementation performs internal sizing - * to try to accommodate this many threads. - * @throws IllegalArgumentException if the initial capacity is - * negative or the load factor or concurrency level are - * non-positive. - */ - public GridConcurrentPhantomHashSet(int initCap, float loadFactor, int conLevel) { - store = new GridConcurrentHashSet<>(initCap, loadFactor, conLevel); - } - - /** - * Constructs a new set containing the elements in the specified - * collection, with default load factor and an initial - * capacity sufficient to contain the elements in the specified collection. - * - * @param c Collection to add. - */ - public GridConcurrentPhantomHashSet(Collection c) { - this(c.size()); - - addAll(c); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"SimplifiableIfStatement"}) - @Override public boolean add(E e) { - A.notNull(e, "e"); - - removeStale(); - - if (!contains(e)) - return store.add(fact.apply(e)); - - return false; - } - - /** {@inheritDoc} */ - @Override public boolean addAll(@Nullable Collection c) { - boolean res = false; - - if (!F.isEmpty(c)) { - assert c != null; - - for (E e : c) { - res |= add(e); - } - } - - return res; - } - - /** {@inheritDoc} */ - @Override public boolean retainAll(@Nullable Collection c) { - removeStale(); - - boolean res = false; - - if (!F.isEmpty(c)) { - assert c != null; - - Iterator> iter = store.iterator(); - - while (iter.hasNext()) { - if (!c.contains(iter.next().get())) { - iter.remove(); - - res = true; - } - } - } - - return res; - } - - /** {@inheritDoc} */ - @Override public int size() { - removeStale(); - - return store.size(); - } - - /** {@inheritDoc} */ - @Override public boolean isEmpty() { - removeStale(); - - return store.isEmpty(); - } - - /** {@inheritDoc} */ - @Override public boolean contains(@Nullable Object o) { - removeStale(); - - if (!store.isEmpty() && o != null) { - for (PhantomReferenceElement ref : store) { - Object reft = ref.get(); - - if (reft != null && reft.equals(o)) - return true; - } - } - - return false; - } - - /** {@inheritDoc} */ - @Override public boolean containsAll(@Nullable Collection c) { - if (F.isEmpty(c)) - return false; - - assert c != null; - - for (Object o : c) { - if (!contains(o)) - return false; - } - - return true; - } - - /** {@inheritDoc} */ - @Override public Object[] toArray() { - return toArray(EMPTY_ARR); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"SuspiciousToArrayCall"}) - @Override public T[] toArray(T[] a) { - removeStale(); - - Collection elems = new LinkedList<>(); - - for (PhantomReferenceElement ref : store) { - E e = ref.get(); - - if (e != null) - elems.add(e); - } - - return elems.toArray(a); - } - - /** {@inheritDoc} */ - @Override public Iterator iterator() { - removeStale(); - - return new Iterator() { - /** Storage iterator. */ - private Iterator> iter = store.iterator(); - - /** Current element. */ - private E elem; - - /** {@inheritDoc} */ - @Override public boolean hasNext() { - if (elem == null) { - while (iter.hasNext()) { - PhantomReferenceElement ref = iter.next(); - - E e; - - if (ref != null && (e = ref.get()) != null) { - elem = e; - - break; - } - else - removeStale(); - } - } - - return elem != null; - } - - /** {@inheritDoc} */ - @Override public E next() { - if (elem == null) { - if (!hasNext()) - throw new NoSuchElementException(); - } - - E res = elem; - - elem = null; - - return res; - } - - /** {@inheritDoc} */ - @Override public void remove() { - iter.remove(); - } - }; - } - - /** {@inheritDoc} */ - @Override public void clear() { - store.clear(); - } - - /** {@inheritDoc} */ - @Override public boolean remove(@Nullable Object o) { - removeStale(); - - if (o != null) { - for (Iterator> iter = store.iterator(); iter.hasNext();) { - Object reft = iter.next().get(); - - if (reft != null && reft.equals(o)) { - iter.remove(); - - return true; - } - } - } - - return false; - } - - /** {@inheritDoc} */ - @Override public boolean removeAll(@Nullable Collection c) { - boolean res = false; - - if (!F.isEmpty(c)) { - assert c != null; - - for (Object o : c) { - res |= remove(o); - } - } - - return res; - } - - /** {@inheritDoc} */ - @Override public boolean equals(@Nullable Object o) { - if (this == o) - return true; - - if (!(o instanceof GridConcurrentPhantomHashSet)) - return false; - - GridConcurrentPhantomHashSet that = (GridConcurrentPhantomHashSet)o; - - return store.equals(that.store); - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return store.hashCode(); - } - - /** - * Removes stale references. - */ - private void removeStale() { - PhantomReferenceElement ref; - - while ((ref = (PhantomReferenceElement)refQ.poll()) != null) { - store.remove(ref); - - onGc(ref.get()); - } - } - - /** - * This method is called on every element when it gets GC-ed. - * - * @param e Element that is about to get GC-ed. - */ - protected void onGc(E e) { - // No-op. - } - - /** - * Phantom reference implementation for this set. - */ - private static class PhantomReferenceElement extends PhantomReference { - /** Element hash code. */ - private int hashCode; - - /** - * Creates weak reference element. - * - * @param ref Referent. - * @param refQ Reference queue. - */ - private PhantomReferenceElement(E ref, ReferenceQueue refQ) { - super(ref, refQ); - - hashCode = ref != null ? ref.hashCode() : 0; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (!(o instanceof PhantomReferenceElement)) - return false; - - E thisRef = get(); - - Object thatRef = ((Reference)o).get(); - - return thisRef != null ? thisRef.equals(thatRef) : thatRef == null; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return hashCode; - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridConcurrentPhantomHashSet.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridFixedSizeInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridFixedSizeInputStream.java deleted file mode 100644 index 9383df2772ab5..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridFixedSizeInputStream.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Input stream wrapper which allows to read exactly expected number of bytes. - */ -public class GridFixedSizeInputStream extends InputStream { - /** */ - private final InputStream in; - - /** */ - private long size; - - /** - * @param in Input stream. - * @param size Size of available data. - */ - public GridFixedSizeInputStream(InputStream in, long size) { - this.in = in; - this.size = size; - } - - /** {@inheritDoc} */ - @Override public int read(byte[] b, int off, int len) throws IOException { - assert len <= b.length; - - if (size == 0) - return -1; - - if (len > size) - // Assignment is ok because size < len <= Integer.MAX_VALUE - len = (int)size; - - int res = in.read(b, off, len); - - if (res == -1) - throw new IOException("Expected " + size + " more bytes to read."); - - assert res >= 0 : res; - - size -= res; - - assert size >= 0 : size; - - return res; - } - - /** {@inheritDoc} */ - @Override public int available() throws IOException { - return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)size; - } - - /** {@inheritDoc} */ - @Override public int read() throws IOException { - if (size == 0) - return -1; - - int res = in.read(); - - if (res == -1) - throw new IOException("Expected " + size + " more bytes to read."); - - size--; - - return res; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridMutex.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridMutex.java deleted file mode 100644 index ecd53ffcf93d9..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridMutex.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import org.apache.ignite.internal.util.typedef.internal.S; - -/** - * Serializable mutex. - */ -public class GridMutex implements Externalizable, Cloneable { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public Object clone() { - try { - return super.clone(); - } - catch (CloneNotSupportedException ignore) { - throw new InternalError(); - } - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridMutex.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableIterable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableIterable.java deleted file mode 100644 index 525989f9e5f93..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableIterable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.Serializable; - -/** - * Makes {@link Iterable} as {@link Serializable} and is - * useful for making anonymous serializable iterators. - */ -public interface GridSerializableIterable extends Iterable, Serializable { - // No-op. -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableList.java deleted file mode 100644 index b3acb914f732b..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSerializableList.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.Serializable; -import java.util.AbstractList; - -/** - * Makes {@link AbstractList} as {@link Serializable} and is - * useful for making anonymous serializable lists. It has no - * extra logic or state in addition to {@link AbstractList}. - */ -public abstract class GridSerializableList extends AbstractList implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - // No-op. -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSpiCloseableIteratorWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridSpiCloseableIteratorWrapper.java deleted file mode 100644 index a507321e38208..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSpiCloseableIteratorWrapper.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.util.lang.GridCloseableIterator; -import org.apache.ignite.spi.IgniteSpiCloseableIterator; - -/** - * Wrapper used to covert {@link org.apache.ignite.spi.IgniteSpiCloseableIterator} to {@link GridCloseableIterator}. - */ -public class GridSpiCloseableIteratorWrapper extends GridCloseableIteratorAdapter { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final IgniteSpiCloseableIterator iter; - - /** - * @param iter Spi iterator. - */ - public GridSpiCloseableIteratorWrapper(IgniteSpiCloseableIterator iter) { - assert iter != null; - - this.iter = iter; - } - - /** {@inheritDoc} */ - @Override protected T onNext() throws IgniteCheckedException { - return iter.next(); - } - - /** {@inheritDoc} */ - @Override protected boolean onHasNext() throws IgniteCheckedException { - return iter.hasNext(); - } - - /** {@inheritDoc} */ - @Override protected void onClose() throws IgniteCheckedException { - iter.close(); - } - - /** {@inheritDoc} */ - @Override protected void onRemove() throws IgniteCheckedException { - iter.remove(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSynchronizedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridSynchronizedMap.java deleted file mode 100644 index d997944dff2f3..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridSynchronizedMap.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Synchronized map for cache values that is safe to update in-place. Main reason for this map - * is to provide snapshot-guarantee for serialization and keep concurrent iterators. - */ -public class GridSynchronizedMap extends ConcurrentHashMap implements Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public synchronized V putIfAbsent(K key, V val) { - return super.putIfAbsent(key, val); - } - - /** {@inheritDoc} */ - @Override public synchronized boolean remove(Object key, Object val) { - return super.remove(key, val); - } - - /** {@inheritDoc} */ - @Override public synchronized boolean replace(K key, V oldVal, V newVal) { - return super.replace(key, oldVal, newVal); - } - - /** {@inheritDoc} */ - @Override public synchronized V replace(K key, V val) { - return super.replace(key, val); - } - - /** {@inheritDoc} */ - @Override public synchronized V put(K key, V val) { - return super.put(key, val); - } - - /** {@inheritDoc} */ - @Override public synchronized V remove(Object key) { - return super.remove(key); - } - - /** {@inheritDoc} */ - @Override public synchronized void putAll(Map m) { - super.putAll(m); - } - - /** {@inheritDoc} */ - @Override public synchronized void clear() { - super.clear(); - } - - /** {@inheritDoc} */ - @Override public synchronized void writeExternal(ObjectOutput out) throws IOException { - int size = size(); - - out.writeInt(size); - - for (Entry entry : entrySet()) { - out.writeObject(entry.getKey()); - out.writeObject(entry.getValue()); - - size--; - } - - assert size == 0 : "Invalid number of entries written: " + size; - } - - /** {@inheritDoc} */ - @Override public synchronized void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - int size = in.readInt(); - - for (int i = 0; i < size; i++) - put((K)in.readObject(), (V)in.readObject()); - - int mapSize = size(); - - assert mapSize == size : "Invalid map size after reading [size=" + size + ", mapSize=" + size + ']'; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridWeakIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridWeakIterator.java deleted file mode 100644 index 6fce7106d7016..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridWeakIterator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.util.Iterator; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.util.lang.GridCloseableIterator; - -/** - * Weak iterator. - */ -public class GridWeakIterator extends WeakReference> { - /** Nested closeable iterator. */ - private final GridCloseableIterator it; - - /** - * @param ref Referent. - * @param it Closeable iterator. - * @param q Referent queue. - */ - public GridWeakIterator(Iterator ref, GridCloseableIterator it, - ReferenceQueue> q) { - super(ref, q); - - assert it != null; - - this.it = it; - } - - /** - * Closes iterator. - * - * @throws IgniteCheckedException If failed. - */ - public void close() throws IgniteCheckedException { - it.close(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/IgniteRemoteMapTask.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/IgniteRemoteMapTask.java deleted file mode 100644 index e2812569bc7fd..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/IgniteRemoteMapTask.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.future; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCompute; -import org.apache.ignite.IgniteException; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.compute.ComputeJob; -import org.apache.ignite.compute.ComputeJobAdapter; -import org.apache.ignite.compute.ComputeJobContext; -import org.apache.ignite.compute.ComputeJobResult; -import org.apache.ignite.compute.ComputeTask; -import org.apache.ignite.compute.ComputeTaskAdapter; -import org.apache.ignite.compute.ComputeTaskFuture; -import org.apache.ignite.internal.processors.task.GridInternal; -import org.apache.ignite.lang.IgniteFuture; -import org.apache.ignite.lang.IgniteInClosure; -import org.apache.ignite.resources.IgniteInstanceResource; -import org.apache.ignite.resources.JobContextResource; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Util task that will execute ComputeTask on a given node. - */ -@GridInternal public class IgniteRemoteMapTask extends ComputeTaskAdapter { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final ClusterNode node; - - /** */ - private final ComputeTask remoteTask; - - /** - * @param node Target node. - * @param remoteTask Delegate task. - */ - public IgniteRemoteMapTask(ClusterNode node, ComputeTask remoteTask) { - this.node = node; - this.remoteTask = remoteTask; - } - - /** {@inheritDoc} */ - @NotNull @Override public Map map(List subgrid, - @Nullable T arg) throws IgniteException { - - for (ClusterNode node : subgrid) { - if (node.equals(this.node)) - return Collections.singletonMap(new Job<>(remoteTask, arg), node); - } - - throw new IgniteException("Node " + node + " is not present in subgrid."); - } - - /** {@inheritDoc} */ - @Nullable @Override public R reduce(List results) throws IgniteException { - assert results.size() == 1; - - return results.get(0).getData(); - } - - /** - * - */ - private static class Job extends ComputeJobAdapter { - /** */ - private static final long serialVersionUID = 0L; - - /** Auto-inject job context. */ - @JobContextResource - private ComputeJobContext jobCtx; - - /** Auto-inject ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - private final ComputeTask remoteTask; - - /** */ - @Nullable private final T arg; - - /** */ - @Nullable private ComputeTaskFuture future; - - /** - * @param remoteTask Remote task. - * @param arg Argument. - */ - public Job(ComputeTask remoteTask, @Nullable T arg) { - this.remoteTask = remoteTask; - this.arg = arg; - } - - /** {@inheritDoc} */ - @Override public Object execute() throws IgniteException { - if (future == null) { - IgniteCompute compute = ignite.compute().withAsync(); - - compute.execute(remoteTask, arg); - - ComputeTaskFuture fut = compute.future(); - - this.future = fut; - - jobCtx.holdcc(); - - fut.listen(new IgniteInClosure>() { - @Override public void apply(IgniteFuture future) { - jobCtx.callcc(); - } - }); - - return null; - } - else { - return future.get(); - } - } - } - -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridReversedLinesFileReader.java b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridReversedLinesFileReader.java deleted file mode 100644 index 12c80a00f4d12..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridReversedLinesFileReader.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.io; - -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.UnsupportedCharsetException; - -/** - * Reads lines in a file reversely (similar to a BufferedReader, but starting at - * the last line). Useful for e.g. searching in log files. - */ -@SuppressWarnings("ALL") -public class GridReversedLinesFileReader implements Closeable { - /** */ - private final int blockSize; - - /** */ - private final Charset encoding; - - /** */ - private final RandomAccessFile randomAccessFile; - - /** */ - private final long totalByteLength; - - /** */ - private final long totalBlockCount; - - /** */ - private final byte[][] newLineSequences; - - /** */ - private final int avoidNewlineSplitBufferSize; - - /** */ - private final int byteDecrement; - - /** */ - private FilePart currentFilePart; - - /** */ - private boolean trailingNewlineOfFileSkipped = false; - - /** - * Creates a ReverseLineReader with default block size of 4KB and the - * platform's default encoding. - * - * @param file - * the file to be read - * @throws IOException if an I/O error occurs - */ - public GridReversedLinesFileReader(final File file) throws IOException { - this(file, 4096, Charset.defaultCharset().toString()); - } - - /** - * Creates a ReverseLineReader with the given block size and encoding. - * - * @param file - * the file to be read - * @param blockSize - * size of the internal buffer (for ideal performance this should - * match with the block size of the underlying file system). - * @param charset - * the encoding of the file - * @throws IOException if an I/O error occurs - * @since 2.3 - */ - public GridReversedLinesFileReader(final File file, final int blockSize, final Charset charset) throws IOException { - this.blockSize = blockSize; - this.encoding = charset; - - randomAccessFile = new RandomAccessFile(file, "r"); - totalByteLength = randomAccessFile.length(); - int lastBlockLength = (int)(totalByteLength % blockSize); - if (lastBlockLength > 0) { - totalBlockCount = totalByteLength / blockSize + 1; - } - else { - totalBlockCount = totalByteLength / blockSize; - if (totalByteLength > 0) { - lastBlockLength = blockSize; - } - } - currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null); - - // --- check & prepare encoding --- - CharsetEncoder charsetEncoder = charset.newEncoder(); - float maxBytesPerChar = charsetEncoder.maxBytesPerChar(); - if (maxBytesPerChar == 1f) { - // all one byte encodings are no problem - byteDecrement = 1; - } - else if (charset == Charset.forName("UTF-8")) { - // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte - // http://en.wikipedia.org/wiki/UTF-8 - byteDecrement = 1; - } - else if (charset == Charset.forName("Shift_JIS")) { - // Same as for UTF-8 - // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html - byteDecrement = 1; - } - else if (charset == Charset.forName("UTF-16BE") || charset == Charset.forName("UTF-16LE")) { - // UTF-16 new line sequences are not allowed as second tuple of four byte sequences, - // however byte order has to be specified - byteDecrement = 2; - } - else if (charset == Charset.forName("UTF-16")) { - throw new UnsupportedEncodingException( - "For UTF-16, you need to specify the byte order (use UTF-16BE or UTF-16LE)"); - } - else { - throw new UnsupportedEncodingException( - "Encoding " + charset + " is not supported yet (feel free to submit a patch)"); - } - // NOTE: The new line sequences are matched in the order given, so it is important that \r\n is BEFORE \n - newLineSequences = new byte[][] {"\r\n".getBytes(charset), "\n".getBytes(charset), "\r".getBytes(charset)}; - - avoidNewlineSplitBufferSize = newLineSequences[0].length; - } - - /** - * Creates a ReverseLineReader with the given block size and encoding. - * - * @param file - * the file to be read - * @param blockSize - * size of the internal buffer (for ideal performance this should - * match with the block size of the underlying file system). - * @param encoding - * the encoding of the file - * @throws IOException if an I/O error occurs - * @throws UnsupportedCharsetException - * thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not - * supported. - */ - public GridReversedLinesFileReader(final File file, final int blockSize, final String encoding) throws IOException { - this(file, blockSize, Charset.forName(encoding)); - } - - /** - * Returns the lines of the file from bottom to top. - * - * @return the next line or null if the start of the file is reached - * @throws IOException if an I/O error occurs - */ - public String readLine() throws IOException { - - String line = currentFilePart.readLine(); - while (line == null) { - currentFilePart = currentFilePart.rollOver(); - if (currentFilePart != null) { - line = currentFilePart.readLine(); - } - else { - // no more fileparts: we're done, leave line set to null - break; - } - } - - // aligned behaviour wiht BufferedReader that doesn't return a last, emtpy line - if ("".equals(line) && !trailingNewlineOfFileSkipped) { - trailingNewlineOfFileSkipped = true; - line = readLine(); - } - - return line; - } - - /** - * Closes underlying resources. - * - * @throws IOException if an I/O error occurs - */ - public void close() throws IOException { - randomAccessFile.close(); - } - - /** */ - private class FilePart { - /** */ - private final long no; - - /** */ - private final byte[] data; - - /** */ - private byte[] leftOver; - - /** */ - private int currentLastBytePos; - - /** - * ctor - * @param no the part number - * @param length its length - * @param leftOverOfLastFilePart remainder - * @throws IOException if there is a problem reading the file - */ - private FilePart(final long no, final int length, final byte[] leftOverOfLastFilePart) throws IOException { - this.no = no; - int dataLength = length + (leftOverOfLastFilePart != null ? leftOverOfLastFilePart.length : 0); - this.data = new byte[dataLength]; - final long off = (no - 1) * blockSize; - - // read data - if (no > 0 /* file not empty */) { - randomAccessFile.seek(off); - final int cntRead = randomAccessFile.read(data, 0, length); - if (cntRead != length) { - throw new IllegalStateException("Count of requested bytes and actually read bytes don't match"); - } - } - // copy left over part into data arr - if (leftOverOfLastFilePart != null) { - System.arraycopy(leftOverOfLastFilePart, 0, data, length, leftOverOfLastFilePart.length); - } - this.currentLastBytePos = data.length - 1; - this.leftOver = null; - } - - /** - * Handles block rollover - * - * @return the new FilePart or null - * @throws IOException if there was a problem reading the file - */ - private FilePart rollOver() throws IOException { - - if (currentLastBytePos > -1) { - throw new IllegalStateException("Current currentLastCharPos unexpectedly positive... " - + "last readLine() should have returned something! currentLastCharPos=" + currentLastBytePos); - } - - if (no > 1) { - return new FilePart(no - 1, blockSize, leftOver); - } - else { - // NO 1 was the last FilePart, we're finished - if (leftOver != null) { - throw new IllegalStateException("Unexpected leftover of the last block: leftOverOfThisFilePart=" - + new String(leftOver, encoding)); - } - return null; - } - } - - /** - * Reads a line. - * - * @return the line or null - * @throws IOException if there is an error reading from the file - */ - private String readLine() throws IOException { - - String line = null; - int newLineMatchByteCnt; - - boolean isLastFilePart = no == 1; - - int i = currentLastBytePos; - while (i > -1) { - - if (!isLastFilePart && i < avoidNewlineSplitBufferSize) { - // avoidNewlineSplitBuffer: for all except the last file part we - // take a few bytes to the next file part to avoid splitting of newlines - createLeftOver(); - break; // skip last few bytes and leave it to the next file part - } - - // --- check for newline --- - if ((newLineMatchByteCnt = getNewLineMatchByteCount(data, i)) > 0 /* found newline */) { - final int lineStart = i + 1; - int lineLengthBytes = currentLastBytePos - lineStart + 1; - - if (lineLengthBytes < 0) { - throw new IllegalStateException("Unexpected negative line length=" + lineLengthBytes); - } - byte[] lineData = new byte[lineLengthBytes]; - System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes); - - line = new String(lineData, encoding); - - currentLastBytePos = i - newLineMatchByteCnt; - break; // found line - } - - // --- move cursor --- - i -= byteDecrement; - - // --- end of file part handling --- - if (i < 0) { - createLeftOver(); - break; // end of file part - } - } - - // --- last file part handling --- - if (isLastFilePart && leftOver != null) { - // there will be no line break anymore, this is the first line of the file - line = new String(leftOver, encoding); - leftOver = null; - } - - return line; - } - - /** - * Creates the buffer containing any left over bytes. - */ - private void createLeftOver() { - int lineLengthBytes = currentLastBytePos + 1; - if (lineLengthBytes > 0) { - // create left over for next block - leftOver = new byte[lineLengthBytes]; - System.arraycopy(data, 0, leftOver, 0, lineLengthBytes); - } - else { - leftOver = null; - } - currentLastBytePos = -1; - } - - /** - * Finds the new-line sequence and return its length. - * - * @param data buffer to scan - * @param i start offset in buffer - * @return length of newline sequence or 0 if none found - */ - private int getNewLineMatchByteCount(byte[] data, int i) { - for (byte[] newLineSeq : newLineSequences) { - boolean match = true; - for (int j = newLineSeq.length - 1; j >= 0; j--) { - int k = i + j - (newLineSeq.length - 1); - match &= k >= 0 && data[k] == newLineSeq[j]; - } - if (match) { - return newLineSeq.length; - } - } - return 0; - } - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridPeerDeployAwareAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridPeerDeployAwareAdapter.java deleted file mode 100644 index 17ceb5e356344..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridPeerDeployAwareAdapter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.lang; - -import org.apache.ignite.internal.util.typedef.internal.U; - -/** - * Adapter for common interfaces in closures, reducers and predicates. - */ -public class GridPeerDeployAwareAdapter implements GridPeerDeployAware { - /** */ - private static final long serialVersionUID = 0L; - - /** Peer deploy aware class. */ - protected transient GridPeerDeployAware pda; - - /** - * Sets object that from which peer deployment information - * will be copied, i.e. this lambda object will be peer deployed - * using the same class loader as given object. - *

- * Note that in most cases Ignite attempts to automatically call this - * method whenever lambda classes like closures and predicates are created that - * wrap user object (the peer deploy information in such cases will be copied - * from the user object). - *

- * In general, if user gets class not found exception during peer loading it is - * very likely that peer deploy information was lost during wrapping of one object - * into another. - * - * @param obj Peer deploy aware. - */ - public void peerDeployLike(Object obj) { - assert obj != null; - - pda = U.peerDeployAware(obj); - } - - /** {@inheritDoc} */ - @Override public Class deployClass() { - if (pda == null) - pda = U.detectPeerDeployAware(this); - - return pda.deployClass(); - } - - /** {@inheritDoc} */ - @Override public ClassLoader classLoader() { - if (pda == null) - pda = U.detectPeerDeployAware(this); - - return pda.classLoader(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTriple.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTriple.java deleted file mode 100644 index 18846f3400dbc..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTriple.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.lang; - -import java.io.Externalizable; -import org.jetbrains.annotations.Nullable; - -/** - * Simple extension over {@link GridTuple3} for three objects of the same type. - */ -public class GridTriple extends GridTuple3 { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Empty constructor required by {@link Externalizable}. - */ - public GridTriple() { - // No-op. - } - - /** - * Creates triple with given objects. - * - * @param t1 First object in triple. - * @param t2 Second object in triple. - * @param t3 Third object in triple. - */ - public GridTriple(@Nullable T t1, @Nullable T t2, @Nullable T t3) { - super(t1, t2, t3); - } - - /** {@inheritDoc} */ - @Override public Object clone() { - return super.clone(); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/LongSumReducer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/LongSumReducer.java deleted file mode 100644 index 8b5d6dc496128..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/LongSumReducer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.lang.gridfunc; - -import java.util.concurrent.atomic.AtomicLong; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.lang.IgniteReducer; - -/** - * Reducer that calculates sum of long integer elements. - */ -public class LongSumReducer implements IgniteReducer { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private AtomicLong sum = new AtomicLong(0); - - /** {@inheritDoc} */ - @Override public boolean collect(Long e) { - if (e != null) - sum.addAndGet(e); - - return true; - } - - /** {@inheritDoc} */ - @Override public Long reduce() { - return sum.get(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(LongSumReducer.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/MapFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/MapFactoryCallable.java deleted file mode 100644 index ff5981769ca81..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/MapFactoryCallable.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.lang.gridfunc; - -import java.util.HashMap; -import java.util.Map; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.lang.IgniteCallable; - -/** - * Hash map factory. - */ -public class MapFactoryCallable implements IgniteCallable { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override public Map call() { - return new HashMap(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(MapFactoryCallable.class, this); - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/TransformMapView2.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/TransformMapView2.java deleted file mode 100644 index 9361e5575a95e..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/TransformMapView2.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util.lang.gridfunc; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import org.apache.ignite.internal.util.GridSerializableMap; -import org.apache.ignite.internal.util.GridSerializableSet; -import org.apache.ignite.internal.util.lang.GridFunc; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.lang.IgniteBiClosure; -import org.apache.ignite.lang.IgnitePredicate; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Light-weight view on given map with provided predicate and clos. - * - * @param Type of the key. - * @param Type of the input map value. - * @param Type of the output map value. - */ -public class TransformMapView2 extends GridSerializableMap { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final Map map; - - /** */ - private final IgniteBiClosure clos; - - /** */ - private final IgnitePredicate[] preds; - - /** Entry predicate. */ - private IgnitePredicate> entryPred; - - /** - * @param map Input map that serves as a base for the view. - * @param clos Transformer for map value transformation. - * @param preds Optional predicates. If predicates are not provided - all will be in the view. - */ - @SuppressWarnings({"unchecked"}) - public TransformMapView2(Map map, IgniteBiClosure clos, - IgnitePredicate... preds) { - this.map = map; - this.clos = clos; - this.preds = preds; - entryPred = new EntryByKeyEvaluationPredicate(preds); - } - - /** {@inheritDoc} */ - @NotNull @Override public Set> entrySet() { - return new GridSerializableSet>() { - @NotNull - @Override public Iterator> iterator() { - return new Iterator>() { - private Iterator> it = GridFunc.iterator0(map.entrySet(), true, entryPred); - - @Override public boolean hasNext() { - return it.hasNext(); - } - - @Override public Entry next() { - final Entry e = it.next(); - - return new Entry() { - @Override public K getKey() { - return e.getKey(); - } - - @Override public V1 getValue() { - return clos.apply(e.getKey(), e.getValue()); - } - - @Override public V1 setValue(V1 val) { - throw new UnsupportedOperationException( - "Put is not supported for readonly map view."); - } - }; - } - - @Override public void remove() { - throw new UnsupportedOperationException("Remove is not support for readonly map view."); - } - }; - } - - @Override public int size() { - return F.size(map.keySet(), preds); - } - - @Override public boolean remove(Object o) { - throw new UnsupportedOperationException("Remove is not support for readonly map view."); - } - - @Override public boolean contains(Object o) { - return F.isAll((Entry)o, entryPred) && map.entrySet().contains(o); - } - - @Override public boolean isEmpty() { - return !iterator().hasNext(); - } - }; - } - - /** {@inheritDoc} */ - @Override public boolean isEmpty() { - return entrySet().isEmpty(); - } - - /** {@inheritDoc} */ - @Nullable @Override public V1 get(Object key) { - if (GridFunc.isAll((K)key, preds)) { - V v = map.get(key); - - if (v != null) - return clos.apply((K)key, v); - } - - return null; - } - - /** {@inheritDoc} */ - @Nullable @Override public V1 put(K key, V1 val) { - throw new UnsupportedOperationException("Put is not supported for readonly map view."); - } - - /** {@inheritDoc} */ - @Override public V1 remove(Object key) { - throw new UnsupportedOperationException("Remove is not supported for readonly map view."); - } - - /** {@inheritDoc} */ - @Override public boolean containsKey(Object key) { - return GridFunc.isAll((K)key, preds) && map.containsKey(key); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(TransformMapView2.class, this); - } -} diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 04ceccd84b4c8..931395d4b7e35 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -1267,7 +1267,6 @@ org.apache.ignite.internal.processors.cache.persistence.file.EncryptedFileIOFact org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager$IdxCacheStores org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory -org.apache.ignite.internal.processors.cache.persistence.file.UnzipFileIOFactory org.apache.ignite.internal.processors.cache.persistence.freelist.CorruptedFreeListException org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask org.apache.ignite.internal.processors.cache.persistence.migration.UpgradePendingTreeToPerPartitionTask @@ -1903,14 +1902,8 @@ org.apache.ignite.internal.util.GridBoundedLinkedHashSet org.apache.ignite.internal.util.GridBoundedPriorityQueue org.apache.ignite.internal.util.GridByteArrayList org.apache.ignite.internal.util.GridCloseableIteratorAdapter -org.apache.ignite.internal.util.GridCloseableIteratorAdapterEx -org.apache.ignite.internal.util.GridCollections$LockedCollection -org.apache.ignite.internal.util.GridCollections$LockedList -org.apache.ignite.internal.util.GridCollections$LockedMap -org.apache.ignite.internal.util.GridCollections$LockedSet org.apache.ignite.internal.util.GridConcurrentHashSet org.apache.ignite.internal.util.GridConcurrentLinkedHashSet -org.apache.ignite.internal.util.GridConcurrentPhantomHashSet$1 org.apache.ignite.internal.util.GridConcurrentSkipListSet org.apache.ignite.internal.util.GridConcurrentWeakHashSet$1 org.apache.ignite.internal.util.GridConsistentHash$1 @@ -1933,21 +1926,16 @@ org.apache.ignite.internal.util.GridLogThrottle$LogLevel$1 org.apache.ignite.internal.util.GridLogThrottle$LogLevel$2 org.apache.ignite.internal.util.GridLogThrottle$LogLevel$3 org.apache.ignite.internal.util.GridLongList -org.apache.ignite.internal.util.GridMutex org.apache.ignite.internal.util.GridPartitionStateMap org.apache.ignite.internal.util.GridRandom org.apache.ignite.internal.util.GridReflectionCache org.apache.ignite.internal.util.GridSerializableCollection -org.apache.ignite.internal.util.GridSerializableIterable org.apache.ignite.internal.util.GridSerializableIterator -org.apache.ignite.internal.util.GridSerializableList org.apache.ignite.internal.util.GridSerializableMap org.apache.ignite.internal.util.GridSerializableSet org.apache.ignite.internal.util.GridSetWrapper org.apache.ignite.internal.util.GridSnapshotLock$Sync -org.apache.ignite.internal.util.GridSpiCloseableIteratorWrapper org.apache.ignite.internal.util.GridStringBuilder -org.apache.ignite.internal.util.GridSynchronizedMap org.apache.ignite.internal.util.HostAndPortRange org.apache.ignite.internal.util.IgniteExceptionRegistry$ExceptionInfo org.apache.ignite.internal.util.IgniteTree$OperationType @@ -1995,9 +1983,6 @@ org.apache.ignite.internal.util.future.GridEmbeddedFuture$AsyncListener2 org.apache.ignite.internal.util.future.GridFutureChainListener org.apache.ignite.internal.util.future.IgniteFutureImpl$1 org.apache.ignite.internal.util.future.IgniteFutureImpl$InternalFutureListener -org.apache.ignite.internal.util.future.IgniteRemoteMapTask -org.apache.ignite.internal.util.future.IgniteRemoteMapTask$Job -org.apache.ignite.internal.util.future.IgniteRemoteMapTask$Job$1 org.apache.ignite.internal.util.io.GridFilenameUtils$IOCase org.apache.ignite.internal.util.lang.GridAbsClosure org.apache.ignite.internal.util.lang.GridAbsClosureX @@ -2013,8 +1998,6 @@ org.apache.ignite.internal.util.lang.GridMapEntry org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter$EntryKey org.apache.ignite.internal.util.lang.GridNodePredicate org.apache.ignite.internal.util.lang.GridPeerDeployAware -org.apache.ignite.internal.util.lang.GridPeerDeployAwareAdapter -org.apache.ignite.internal.util.lang.GridTriple org.apache.ignite.internal.util.lang.GridTuple org.apache.ignite.internal.util.lang.GridTuple3 org.apache.ignite.internal.util.lang.GridTuple4 @@ -2061,8 +2044,6 @@ org.apache.ignite.internal.util.lang.gridfunc.IntSumReducer org.apache.ignite.internal.util.lang.gridfunc.IsAllPredicate org.apache.ignite.internal.util.lang.gridfunc.IsNotAllPredicate org.apache.ignite.internal.util.lang.gridfunc.IsNotNullPredicate -org.apache.ignite.internal.util.lang.gridfunc.LongSumReducer -org.apache.ignite.internal.util.lang.gridfunc.MapFactoryCallable org.apache.ignite.internal.util.lang.gridfunc.MultipleIterator org.apache.ignite.internal.util.lang.gridfunc.NoOpClosure org.apache.ignite.internal.util.lang.gridfunc.NotContainsPredicate @@ -2084,8 +2065,6 @@ org.apache.ignite.internal.util.lang.gridfunc.TransformCollectionView org.apache.ignite.internal.util.lang.gridfunc.TransformFilteringIterator org.apache.ignite.internal.util.lang.gridfunc.TransformMapView org.apache.ignite.internal.util.lang.gridfunc.TransformMapView$1 -org.apache.ignite.internal.util.lang.gridfunc.TransformMapView2 -org.apache.ignite.internal.util.lang.gridfunc.TransformMapView2$1 org.apache.ignite.internal.util.nio.GridNioEmbeddedFuture$1 org.apache.ignite.internal.util.nio.GridNioException org.apache.ignite.internal.util.nio.GridNioMessageTracker diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloaderTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloaderTest.java deleted file mode 100644 index cbe399624536b..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/file/FileDownloaderTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.persistence.file; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.InetSocketAddress; -import java.nio.channels.SocketChannel; -import java.nio.file.Files; -import java.nio.file.Path; -import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.junit.Test; - -import static org.apache.ignite.testframework.GridTestUtils.runAsync; -import static org.junit.Assert.assertArrayEquals; - -/** - * FileDownloader test - */ -public class FileDownloaderTest extends GridCommonAbstractTest { - /** */ - private static final Path DOWNLOADER_PATH = new File("download").toPath(); - - /** */ - private static final Path UPLOADER_PATH = new File("upload").toPath(); - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - if (DOWNLOADER_PATH.toFile().exists()) - DOWNLOADER_PATH.toFile().delete(); - - if (UPLOADER_PATH.toFile().exists()) - UPLOADER_PATH.toFile().delete(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - if (DOWNLOADER_PATH.toFile().exists()) - DOWNLOADER_PATH.toFile().delete(); - - if (UPLOADER_PATH.toFile().exists()) - UPLOADER_PATH.toFile().delete(); - } - - /*** - * - * @throws Exception If failed. - */ - @Test - public void test() throws Exception { - assertTrue(UPLOADER_PATH.toFile().createNewFile()); - assertTrue(!DOWNLOADER_PATH.toFile().exists()); - - PrintWriter writer = new PrintWriter(UPLOADER_PATH.toFile()); - - for (int i = 0; i < 1_000_000; i++) - writer.write("HELLO WORLD"); - - writer.close(); - - FileDownloader downloader = new FileDownloader(log, DOWNLOADER_PATH); - - InetSocketAddress addr = downloader.start(); - - GridFutureAdapter finishFut = new GridFutureAdapter<>(); - - FileUploader uploader = new FileUploader(UPLOADER_PATH, log); - - SocketChannel sc = null; - - try { - sc = SocketChannel.open(addr); - } - catch (IOException e) { - U.warn(log, "Fail connect to " + addr, e); - } - - runAsync(downloader::download); - - SocketChannel finalSc = sc; - - runAsync(() -> uploader.upload(finalSc, finishFut)); - - finishFut.get(); - - downloader.onResult(finishFut.get(), null); - - downloader.finishFuture().get(); - - assertTrue(DOWNLOADER_PATH.toFile().exists()); - - assertEquals(UPLOADER_PATH.toFile().length(), DOWNLOADER_PATH.toFile().length()); - - assertArrayEquals(Files.readAllBytes(UPLOADER_PATH), Files.readAllBytes(DOWNLOADER_PATH)); - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java index 986ca50a1f13a..4f23baa58a811 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java @@ -47,7 +47,6 @@ import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsTransactionsHangTest; import org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteDisableWalOnRebalanceTest; import org.apache.ignite.internal.processors.cache.persistence.db.wal.WalRebalanceRestartTest; -import org.apache.ignite.internal.processors.cache.persistence.file.FileDownloaderTest; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.DynamicSuite; import org.junit.runner.RunWith; @@ -71,7 +70,6 @@ public static List> suite(Collection ignoredTests) { addRealPageStoreTestsNotForDirectIo(suite, ignoredTests); - GridTestUtils.addTestIfNeeded(suite, FileDownloaderTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgnitePdsTaskCancelingTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgniteClusterActivateDeactivateTestWithPersistenceAndMemoryReuse.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgnitePdsPartitionPreloadTest.class, ignoredTests);