ShardUtils
Utility methods for distributing a repository across several disks.
Methods
Section titled “Methods”setCurrentShard
Section titled “setCurrentShard”Description:
| Method | Return values | Description |
|---|---|---|
| setCurrentShard(Long shardId) | void | Set the current shard. |
Example:
package com.openkm;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); Long shardId = new Long(1); shardUtils.setCurrentShard(shardId); } catch (Exception e) { e.printStackTrace(); } }}createShardDirs
Section titled “createShardDirs”Description:
| Method | Return values | Description |
|---|---|---|
| createShardDirs(Long shardId) | void | Create a new shard folder. |
Example:
package com.openkm;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); Long shardId = new Long(1); shardUtils.createShardDirs(shardId); } catch (Exception e) { e.printStackTrace(); } }}changeNodeShard
Section titled “changeNodeShard”Description:
| Method | Return values | Description |
|---|---|---|
| changeNodeShard(String uuid, Long newShard) | void | Change the shard of a node. |
Example:
package com.openkm;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); Long newShardId = new Long(2); shardUtils.changeNodeShard("e2391b01-ce10-42c7-94a9-b0d6b394048e", newShardId); } catch (Exception e) { e.printStackTrace(); } }}getShardIds
Section titled “getShardIds”Description:
| Method | Return values | Description |
|---|---|---|
| getShardIds() | List |
Get the shard IDs. |
Example:
package com.openkm;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); for (long id : shardUtils.getShardIds()) { System.out.println(id); } } catch (Exception e) { e.printStackTrace(); } }}getShardSize
Section titled “getShardSize”Description:
| Method | Return values | Description |
|---|---|---|
| getShardSize(Long shardId) | Long | Get the size of a shard. |
Example:
package com.openkm;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); Long shardId = new Long(1); System.out.println(shardUtils.getShardSize(shardId)); } catch (Exception e) { e.printStackTrace(); } }}getShardPaths
Section titled “getShardPaths”Description:
| Method | Return values | Description |
|---|---|---|
| getShardPaths(Long shardId) | List |
Get the paths of a shard. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); Long shardId = new Long(1); List<String> list = shardUtils.getShardPaths(shardId); for (String path : list) { System.out.println(path); } } catch (Exception e) { e.printStackTrace(); } }}getShards
Section titled “getShards”Description:
| Method | Return values | Description |
|---|---|---|
| getShards() | List |
Get the shards. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.db.bean.Shard;import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); List<Shard> list = shardUtils.getShards(); for (Shard shard : list) { System.out.println(shard); } } catch (Exception e) { e.printStackTrace(); } }}getShardFolders
Section titled “getShardFolders”Description:
| Method | Return values | Description |
|---|---|---|
| getShardFolders() | List |
Get the shard folders. |
Example:
package com.openkm;
import java.io.File;import java.util.List;
import com.openkm.util.ContextWrapper;import com.openkm.util.ShardUtils;
public class Test {
public static void main(String[] args) { try { ShardUtils shardUtils = ContextWrapper.getContext().getBean(ShardUtils.class); List<File> list = shardUtils.getShardFolders(); for (File file : list) { System.out.println(file.getPath()); } } catch (Exception e) { e.printStackTrace(); } }}