Exemple #1
0
                void QueryCursorImpl::GetNext(OutputOperation& op, IgniteError& err)
                {
                    // Check whether GetAll() was called earlier.
                    if (getAllCalled) 
                    {
                        err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, 
                            "Cannot use GetNext() method because GetAll() was called.");

                        return;
                    }

                    // Create iterator in Java if needed.
                    if (!CreateIteratorIfNeeded(err))
                        return;

                    // Get next results batch if the end in the current batch
                    // has been reached.
                    if (!GetNextBatchIfNeeded(err))
                        return;

                    if (endReached)
                    {
                        // Ensure we do not overwrite possible previous error.
                        if (err.GetCode() == IgniteError::IGNITE_SUCCESS)
                            err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, "No more elements available.");

                        return;
                    }

                    batch->GetNext(op);
                }
Exemple #2
0
        void Transaction::Rollback(IgniteError & err)
        {
            err = IgniteError();

            TransactionImpl* txImpl = impl.Get();

            if (txImpl)
                txImpl->Rollback(err);
            else
            {
                err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                    "Instance is not usable (did you check for error?).");
            }
        }
Exemple #3
0
        TransactionState::Type Transaction::GetState(IgniteError& err)
        {
            err = IgniteError();

            TransactionImpl* txImpl = impl.Get();

            if (txImpl)
                return txImpl->GetState(err);
            else
            {
                err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                    "Instance is not usable (did you check for error?).");
            }

            return TransactionState::UNKNOWN;
        }
Exemple #4
0
        bool Transaction::IsRollbackOnly(IgniteError& err)
        {
            err = IgniteError();

            TransactionImpl* txImpl = impl.Get();

            if (txImpl)
                return txImpl->IsRollbackOnly(err);
            else
            {
                err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                    "Instance is not usable (did you check for error?).");
            }

            return false;
        }
Exemple #5
0
                    void GetLocalAddresses(std::set<std::string>& addrs)
                    {
                        IP_ADAPTER_ADDRESSES outAddrs[64];

                        DWORD outAddrsSize = sizeof(outAddrs);

                        DWORD error = ::GetAdaptersAddresses(AF_UNSPEC, 0, NULL, &outAddrs[0], &outAddrsSize);

                        if (ERROR_SUCCESS != error)
                            throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");

                        for (IP_ADAPTER_ADDRESSES* outAddr = &outAddrs[0]; NULL != outAddr; outAddr = outAddr->Next)
                        {
                            if (IF_TYPE_SOFTWARE_LOOPBACK == outAddr->IfType)
                                continue;

                            for (IP_ADAPTER_UNICAST_ADDRESS* addr = outAddr->FirstUnicastAddress;
                                NULL != addr;
                                addr = addr->Next)
                            {
                                void *inAddr = 0;
                                
                                char strBuffer[INET6_ADDRSTRLEN] = { 0 };

                                int saFamily = addr->Address.lpSockaddr->sa_family;

                                switch (saFamily)
                                {
                                    case AF_INET:
                                    {
                                        SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(addr->Address.lpSockaddr);
                                        inAddr = &ipv4->sin_addr;

                                        break;
                                    }

                                    case AF_INET6:
                                    {
                                        SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(addr->Address.lpSockaddr);
                                        inAddr = &ipv6->sin6_addr;

                                        break;
                                    }

                                    default:
                                        continue;
                                }

                                inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));

                                std::string strAddr(strBuffer);

                                if (!strAddr.empty())
                                    addrs.insert(strAddr);
                            }
                        }
                    }
Exemple #6
0
            void Configuration::ParseAddress(const std::string& address, EndPoint& res)
            {
                int64_t colonNum = std::count(address.begin(), address.end(), ':');

                if (colonNum == 0)
                {
                    res.host = address;
                    res.port = DefaultValue::port;
                }
                else if (colonNum == 1)
                {
                    size_t pos = address.find(':');

                    if (pos == address.size() - 1)
                        throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Invalid address format: no port after colon");

                    res.host = address.substr(0, pos);

                    std::string port = address.substr(pos + 1);

                    if (!common::AllOf(port.begin(), port.end(), isdigit))
                        throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Invalid address format: port can only contain digits");

                    int32_t intPort = common::LexicalCast<int32_t>(port);

                    if (port.size() > sizeof("65535") - 1 || intPort > UINT16_MAX)
                    {
                        throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Invalid address format: Port value is too large,"
                            " valid value should be in range from 1 to 65535");
                    }

                    if (intPort == 0)
                        throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Invalid address format: Port value can not be zero");

                    res.port = static_cast<uint16_t>(intPort);
                }
                else
                    throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, 
                        "Invalid address format: too many colons");
            }
Exemple #7
0
                void QueryCursorImpl::GetAll(OutputOperation& op, IgniteError& err)
                {
                    // Check whether any of iterator methods were called.
                    if (iterCalled)
                    {
                        err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Cannot use GetAll() method because an iteration method was called.");

                        return;
                    }

                    // Check whether GetAll was called before.
                    if (getAllCalled)
                    {
                        err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Cannot use GetNext() method because GetAll() was called.");

                        return;
                    }

                    // Get data.
                    JniErrorInfo jniErr;

                    SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory();

                    env.Get()->Context()->TargetOutStream(javaRef, OP_GET_ALL, inMem.Get()->PointerLong(), &jniErr);

                    IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);

                    if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
                    {
                        getAllCalled = true;

                        InteropInputStream in(inMem.Get());

                        BinaryReaderImpl reader(&in);

                        op.ProcessOutput(reader);
                    }
                }
Exemple #8
0
        void ThrowLastSetupError()
        {
            DWORD code;
            char msg[BUFFER_SIZE];

            SQLInstallerError(1, &code, msg, sizeof(msg), NULL);

            std::stringstream buf;

            buf << "Message: \"" << msg << "\", Code: " << code;

            throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, buf.str().c_str());
        }
Exemple #9
0
                bool QueryCursorImpl::HasNext(IgniteError& err)
                {
                    // Check whether GetAll() was called earlier.
                    if (getAllCalled) 
                    {
                        err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, 
                            "Cannot use HasNext() method because GetAll() was called.");

                        return false;
                    }

                    // Create iterator in Java if needed.
                    if (!CreateIteratorIfNeeded(err))
                        return false;

                    // Get next results batch if the end in the current batch
                    // has been reached.
                    if (!GetNextBatchIfNeeded(err))
                        return false;

                    return !endReached;
                }
Exemple #10
0
                QueryFieldsRowImpl* QueryCursorImpl::GetNextRow(IgniteError& err)
                {
                    // Create iterator in Java if needed.
                    if (!CreateIteratorIfNeeded(err))
                        return 0;

                    // Get next results batch if the end in the current batch
                    // has been reached.
                    if (!GetNextBatchIfNeeded(err))
                        return 0;

                    if (endReached)
                    {
                        // Ensure we do not overwrite possible previous error.
                        if (err.GetCode() == IgniteError::IGNITE_SUCCESS)
                            err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, "No more elements available.");

                        return 0;
                    }

                    return batch->GetNextRow();
                }
    Ignite Ignition::Get(const char* name, IgniteError* err)
    {
        Ignite res;

        factoryLock.Enter();

        if (started)
        {
            char* name0 = CopyChars(name);

            // 1. Create context for this operation.
            JniErrorInfo jniErr;

            SharedPointer<JniContext> ctx(JniContext::Create(NULL, 0, JniHandlers(), &jniErr));

            IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);

            if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
            {
                // 2. Get environment pointer.
                long long ptr = ctx.Get()->IgnitionEnvironmentPointer(name0, &jniErr);

                IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);

                if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
                {
                    if (ptr != 0)
                    {
                        // 3. Obtain real environment for this instance.
                        JniHandlers* hnds = reinterpret_cast<JniHandlers*>(ptr);

                        SharedPointer<IgniteEnvironment>* env =
                            static_cast<SharedPointer<IgniteEnvironment>*>(hnds->target);

                        // 4. Get fresh node reference.
                        jobject ref = ctx.Get()->IgnitionInstance(name0, &jniErr);

                        if (err->GetCode() == IgniteError::IGNITE_SUCCESS) {
                            if (ref)
                            {
                                IgniteImpl* impl = new IgniteImpl(*env, ref);

                                res = Ignite(impl);
                            }
                            else
                                // Error: concurrent node stop.
                                *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                                    "Failed to get Ignite instance because it was stopped concurrently.");

                        }
                    }
                    else
                        // Error: no node with the given name.
                        *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                            "Failed to get Ignite instance because it is either not started yet or already stopped.");
                }
            }

            ReleaseChars(name0);
        }
        else
            // Error: no node with the given name.
            *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
                "Failed to get Ignite instance because it is either not started yet or already stopped.");

        factoryLock.Leave();

        return res;
    }
    Ignite Ignition::Start(const IgniteConfiguration& cfg, const char* name, IgniteError* err)
    {
        bool failed = false;

        SharedPointer<IgniteEnvironment> env;
        SharedPointer<IgniteEnvironment>* envTarget = NULL;

        jobject javaRef = NULL;

        factoryLock.Enter();

        // 1. Load JVM library if needed.
        if (!JVM_LIB_LOADED)
        {
            bool jvmLibFound;
            std::string jvmLib;

            if (cfg.jvmLibPath)
            {
                std::string jvmLibPath = std::string(cfg.jvmLibPath);

                jvmLib = FindJvmLibrary(&jvmLibPath, &jvmLibFound);
            }
            else
                jvmLib = FindJvmLibrary(NULL, &jvmLibFound);

            if (!jvmLibFound)
            {
                *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_NOT_FOUND,
                    "JVM library is not found (did you set JAVA_HOME environment variable?)");

                failed = true;
            }

            if (!failed) {
                if (!LoadJvmLibrary(jvmLib))
                {
                    *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_LOAD_FAILED, "Failed to load JVM library.");

                    failed = true;
                }
            }

            JVM_LIB_LOADED = true;
        }

        if (!failed)
        {
            // 2. Resolve IGNITE_HOME.
            bool homeFound;
            std::string home;

            if (cfg.igniteHome)
            {
                std::string homePath = std::string(cfg.igniteHome);

                home = ResolveIgniteHome(&homePath, &homeFound);
            }
            else
                home = ResolveIgniteHome(NULL, &homeFound);

            // 3. Create classpath.
            std::string cp;

            if (cfg.jvmClassPath)
            {
                std::string usrCp = cfg.jvmClassPath;

                cp = CreateIgniteClasspath(&usrCp, homeFound ? &home : NULL);
            }
            else
                cp = CreateIgniteClasspath(NULL, homeFound ? &home : NULL);

            if (!cp.empty())
            {
                // 4. Start JVM if needed.
                JniErrorInfo jniErr;

                env = SharedPointer<IgniteEnvironment>(new IgniteEnvironment());

                int optsLen;
                char** opts = CreateJvmOptions(cfg, homeFound ? &home : NULL, cp, &optsLen);

                envTarget = new SharedPointer<IgniteEnvironment>(env);
                
                SharedPointer<JniContext> ctx(
                    JniContext::Create(opts, optsLen, env.Get()->GetJniHandlers(envTarget), &jniErr));

                for (int i = 0; i < optsLen; i++)
                    ReleaseChars(*(opts + i));

                delete[] opts;

                if (!ctx.Get())
                {
                    IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
                    
                    failed = true;
                }

                // 5. Start Ignite.
                if (!failed)
                {
                    char* springCfgPath0 = CopyChars(cfg.springCfgPath);

                    if (!springCfgPath0)
                        springCfgPath0 = CopyChars(DFLT_CFG);

                    char* name0 = CopyChars(name);

                    interop::InteropUnpooledMemory mem(16);
                    interop::InteropOutputStream stream(&mem);
                    stream.WriteBool(false);
                    stream.Synchronize();

                    javaRef = ctx.Get()->IgnitionStart(springCfgPath0, name0, 2, mem.PointerLong(), &jniErr);

                    ReleaseChars(springCfgPath0);
                    ReleaseChars(name0);

                    if (!javaRef) {
                        IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
                        
                        failed = true;
                    }
                    else {
                        // 6. Ignite is started at this point.
                        env.Get()->Initialize(ctx);

                        started = true;
                    }
                }
            }
            else {
                *err = IgniteError(IgniteError::IGNITE_ERR_JVM_NO_CLASSPATH,
                    "Java classpath is empty (did you set IGNITE_HOME environment variable?)");

                failed = true;
            }
        }

        factoryLock.Leave();

        if (failed) 
        {
            if (envTarget)
                delete envTarget;

            return Ignite();
        }
        else 
        {
            IgniteImpl* impl = new IgniteImpl(env, javaRef);

            return Ignite(impl);
        }
    }
 int32_t BinaryObjectImpl::GetEnumValue() const
 {
     throw IgniteError(IgniteError::IGNITE_ERR_BINARY, "GetEnumValue is only supported for enums.");
 }
Exemple #14
0
                bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
                {
                    static common::concurrent::CriticalSection initCs;
                    static bool networkInited = false;

                    // Initing networking if is not inited.
                    if (!networkInited)
                    {
                        common::concurrent::CsLockGuard lock(initCs);
                        if (!networkInited)
                        {
                            WSADATA wsaData;

                            networkInited = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0);

                            if (!networkInited)
                            {
                                std::string err = "Networking initialisation failed: " + GetLastSocketErrorMessage();

                                throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
                            }
                        }
                    }

                    addrinfo hints = { 0 };

                    hints.ai_family = AF_UNSPEC;
                    hints.ai_socktype = SOCK_STREAM;
                    hints.ai_protocol = IPPROTO_TCP;

                    std::stringstream converter;
                    converter << port;

                    // Resolve the server address and port
                    addrinfo *result = NULL;
                    int res = getaddrinfo(hostname, converter.str().c_str(), &hints, &result);

                    if (res != 0)
                        return false;

                    // Attempt to connect to an address until one succeeds
                    for (addrinfo *it = result; it != NULL; it = it->ai_next)
                    {
                        // Create a SOCKET for connecting to server
                        socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);

                        if (socketHandle == INVALID_SOCKET)
                        {
                            std::string err = "Socket creation failed: " + GetLastSocketErrorMessage();

                            throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
                        }

                        TrySetOptions();

                        // Connect to server.
                        res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
                        if (SOCKET_ERROR == res)
                        {
                            int lastError = WSAGetLastError();

                            if (lastError != WSAEWOULDBLOCK)
                            {
                                Close();

                                continue;
                            }

                            res = WaitOnSocket(timeout, false);

                            if (res < 0 || res == WaitResult::TIMEOUT)
                            {
                                Close();

                                continue;
                            }
                        }
                        break;
                    }

                    freeaddrinfo(result);

                    return socketHandle != INVALID_SOCKET;
                }