Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ add_subdirectory(learning-basics)
add_subdirectory(distributed-topic)
add_subdirectory(distributed-primitives)
add_subdirectory(distributed-map)
add_subdirectory(distributed-collections)




Expand Down
19 changes: 19 additions & 0 deletions examples/distributed-collections/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
#
# Licensed 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.
#
add_subdirectory(blockingqueue)
add_subdirectory(itemlisteners)
add_subdirectory(list)
add_subdirectory(set)
18 changes: 18 additions & 0 deletions examples/distributed-collections/blockingqueue/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
#
# Licensed 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.
#
add_executable(blockingqueueconsumer ./Consumer.cpp)
add_executable(blockingqueueproducer ./Producer.cpp)

46 changes: 46 additions & 0 deletions examples/distributed-collections/blockingqueue/Consumer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IQueue<int> queue = hz.getQueue<int>("queue");

while (true) {
boost::shared_ptr<int> item = queue.take();
if (item.get()) {
std::cout << "Consumed: " << *item << std::endl;

if (*item == -1) {
queue.put(-1);
break;
}
} else {
std::cout << "Retrieved item is null." << std::endl;
}
hazelcast::util::sleep(5);
}
std::cout << "Consumer Finished!" << std::endl;

std::cout << "Finished" << std::endl;

return 0;
}
38 changes: 38 additions & 0 deletions examples/distributed-collections/blockingqueue/Producer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IQueue<int> queue = hz.getQueue<int>("queue");

for (int k = 1; k < 100; k++) {
queue.put(k);
std::cout << "Producing: " << k << std::endl;
hazelcast::util::sleep(1);
}
queue.put(-1);
std::cout << "Producer Finished!" << std::endl;

std::cout << "Finished" << std::endl;

return 0;
}
18 changes: 18 additions & 0 deletions examples/distributed-collections/itemlisteners/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
#
# Licensed 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.
#
add_executable(itemlistener ./ItemListener.cpp)
add_executable(collectionchanger ./CollectionChanger.cpp)

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IQueue<std::string> queue = hz.getQueue<std::string>("queue");

queue.put("foo");
queue.put("bar");
queue.take();
queue.take();

std::cout << "Changer Finished!" << std::endl;

std::cout << "Finished" << std::endl;

return 0;
}
78 changes: 78 additions & 0 deletions examples/distributed-collections/itemlisteners/ItemListener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

class ItemListenerImpl : public hazelcast::client::ItemListener<std::string> {
public:

ItemListenerImpl() : numAdded(0), numRemoved(0) {
}

void itemAdded(const hazelcast::client::ItemEvent<std::string> &item) {
std::cout << "Item added:" << item.getItem() << std::endl;
++numAdded;
}

void itemRemoved(const hazelcast::client::ItemEvent<std::string> &item) {
std::cout << "Item removed:" << item.getItem() << std::endl;
++numRemoved;
}


int getNumAdded() const {
return numAdded;
}

int getNumRemoved() const {
return numRemoved;
}

private:
int numAdded;
int numRemoved;
};

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IQueue<std::string> queue = hz.getQueue<std::string>("queue");

ItemListenerImpl listener;
std::string registrationId = queue.addItemListener(listener, true);

std::cout << "Registered the listener with registration id:" << registrationId <<
"Waiting for the listener events!" << std::endl;

hazelcast::util::sleep(5);

std::cout << "Received " << listener.getNumAdded() << " items addition and " << listener.getNumRemoved() <<
" items removal events." << std::endl;

// unregister the listener
if (queue.removeItemListener(registrationId)) {
std::cout << "Removed the item listener with registration id " << registrationId << std::endl;
} else {
std::cout << "Failed to remove the item listener with registration id " << registrationId << std::endl;
}

std::cout << "Finished" << std::endl;

return 0;
}
18 changes: 18 additions & 0 deletions examples/distributed-collections/list/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
#
# Licensed 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.
#
add_executable(listreader ./Reader.cpp)
add_executable(listwriter ./Writer.cpp)

38 changes: 38 additions & 0 deletions examples/distributed-collections/list/Reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IList<std::string> list = hz.getList<std::string>("list");

std::vector<std::string> listValues = list.toArray();

for (std::vector<std::string>::const_iterator it = listValues.begin(); it != listValues.end(); ++it) {
std::cout << *it << std::endl;
}

std::cout << "Reading finished!" << std::endl;

std::cout << "Finished" << std::endl;

return 0;
}
37 changes: 37 additions & 0 deletions examples/distributed-collections/list/Writer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by İhsan Demir on 21/12/15.
//
#include <hazelcast/client/HazelcastClient.h>

int main() {
hazelcast::client::ClientConfig config;
hazelcast::client::HazelcastClient hz(config);

hazelcast::client::IList<std::string> list = hz.getList<std::string>("list");

list.add("Tokyo");
list.add("Paris");
list.add("London");
list.add("New York");

std::cout << "Putting finished!" << std::endl;

std::cout << "Finished" << std::endl;

return 0;
}
18 changes: 18 additions & 0 deletions examples/distributed-collections/set/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
#
# Licensed 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.
#
add_executable(setreader ./Reader.cpp)
add_executable(setwriter ./Writer.cpp)

Loading